Suppose the string is:
string x = "0000000000";
I want to add a seperator like "." after each 3 character group starting from the end.
Output should be :
0.000.000.000
How could I do this?
You need to use the following regex:
(\d)(?=(?:\d{3})+(?!\d))
And replace with $1.
Here is a RegexStorm demo (see Context tab on that page)
var rx = new Regex(@"(\d)(?=(?:\d{3})+(?!\d))");
var res = rx.Replace("0000000000", "$1.");
As a non-regex solution, you can use Batch from MoreLINQ to get equally sized strings and reverse it and combine with string.Join like;
string s = "0000000000";
var group = s.Batch(3, p => new string(p.ToArray())).ToList();
group.Reverse();
var result = string.Join(".", group);
Console.WriteLine(result); // 0.000.000.000