I'm using Regex.Replace
to add a white space after every n
th character into a string. I want to give an int variable(number of characters) after which white space should be added but It seems regular expression is not properly written for int variable and hence syntax error arises.
int num = 8;
string text="abcdefghijklmnop"
string result2 = Regex.Replace(text, ".{num}", "$0 "); //not working
this syntax is working
string result2 = Regex.Replace(text, ".{8}", "$0 ");