Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string str ="abcdefg1234567qwertyuzxcvbnm";
- Console.WriteLine(str);
- void Main()
- {
- string str ="abcdefg1234567qwertyuzxcvbnm";
- string result = SplitStr(str, 7);
- //result.Dump();
- }
- // Define other methods and classes here
- public string SplitStr(string str, int maxSymbols)
- {
- var sb = new StringBuilder();
- var counter = 0;
- foreach (var element in str)
- {
- if (counter == maxSymbols)
- {
- sb.Append(" ");
- counter = 0;
- }
- sb.Append(element);
- counter++;
- }
- return sb.ToString();
- }
- string str = "abcdefg1234567qwertyuzxcvbnm";
- string res = Regex.Replace(str, ".{7}", "$0 ");
- Console.WriteLine(res);
Add Comment
Please, Sign In to add comment