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");
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");
 
    
    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?
        String abc = "123456789012";
        for (int i = 4; i <= abc.Length; i += 4)
        {
            abc = abc.Insert(i, " ");
            i++;
        }
 
    
    public string InsertSpaces(string s)
{
    char[] result = new char[s.Length + (s.Length / 4)];
    for (int i = 0, target = 0; i < s.Length; i++)
    {
        result[target++] = s[i];
        if (i & 3 == 3)
            result[target++] = ' ';
    }
    return new string(result);
}
