I have only recently started studying Xamarin and I need your help. I saw something what I want on this link How can I create effect hide numbers the credit card except the last 3 numbers
But I do not how I can do it on C#.
I have only recently started studying Xamarin and I need your help. I saw something what I want on this link How can I create effect hide numbers the credit card except the last 3 numbers
But I do not how I can do it on C#.
You have to create converter for this, here is in example. Just replace what you want in your logic in this and it will work.
public class CreditCardNumberValueConverter : IValueConverter
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var builder = new StringBuilder(Regex.Replace(value.ToString(), @"\D", ""));
foreach (var i in Enumerable.Range(0, builder.Length / 4).Reverse())
builder.Insert(4*i + 4, " ");
return builder.ToString().Trim();
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Regex.Replace(value.ToString(), @"\D", "");
}
}
Then use it from xaml like:
Text="{Binding CardNo, Converter={StaticResource CreditCardNumberValueConverter}}"
2 Solution:
string MaskDigits(string input)
{
//take first 8 characters
string firstPart = input.Substring(0, 8);
//take last 4 characters
int len = input.Length;
string lastPart = input.Substring(len - 4, 4);
string maskedDigits = new String('*', 4);
return firstPart + maskedDigits;
}