The string displays value as:
123456789012
I need it like:
1234 5678 9012
There should be space between every 4 characters in this string. How do I do that?
displaynum_lbl.Text = Regex.Replace(printClass.mynumber.ToString(), ".{4}", "$0");
String abc = "123456789012";
for (int i = 4; i <= abc.Length; i += 4)
{
abc = abc.Insert(i, " ");
i++;
}
Assuming that it's fine to work from right-to-left, this should do the trick:
displaynum_lbl.Text = System.Text.RegularExpressions.Regex.Replace(printClass.mynumber.ToString(), ".{4}", "$0 ");
You can find that and a good deal more information in other StackOverflow answers, example: Add separator to string at every N characters?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With