Guest User

Untitled

a guest
Dec 6th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. string str ="abcdefg1234567qwertyuzxcvbnm";
  2.  
  3. Console.WriteLine(str);
  4.  
  5. void Main()
  6. {
  7. string str ="abcdefg1234567qwertyuzxcvbnm";
  8. string result = SplitStr(str, 7);
  9. //result.Dump();
  10. }
  11.  
  12. // Define other methods and classes here
  13.  
  14. public string SplitStr(string str, int maxSymbols)
  15. {
  16. var sb = new StringBuilder();
  17. var counter = 0;
  18. foreach (var element in str)
  19. {
  20. if (counter == maxSymbols)
  21. {
  22. sb.Append(" ");
  23. counter = 0;
  24. }
  25.  
  26. sb.Append(element);
  27. counter++;
  28. }
  29. return sb.ToString();
  30. }
  31.  
  32. string str = "abcdefg1234567qwertyuzxcvbnm";
  33. string res = Regex.Replace(str, ".{7}", "$0 ");
  34. Console.WriteLine(res);
Add Comment
Please, Sign In to add comment