I want to add one space after every two characters and add a character in front of each character.
This is my code:
string str2;
str2 = str1.ToCharArray().Aggregate("", (result, c) => result += ((!string.IsNullOrEmpty(result) && (result.Length + 1) % 3 == 0) ? " " : "") + c.ToString());
I have no problem dividing every two characters with one space, but how do I know if the selected text has a separate character and adds the infront character to that character?
I understand that my question is confused because I am not sure how to put what I want in words. So I’ll just give an example:
I have this line:
0123457
Separating every two characters with a space, I get:
01 23 45 7
I want to add 6 infront of 7.
Note. Numbers depend on user input, so it is not always the same.
Thank.
source
share