Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. //Console.WriteLine("Hello");
  9.  
  10. string somestring = "We have disbaled network access for free pads due to abouse.";
  11. PrintString(somestring, 15);
  12. //Whole sentace to be broken and adjusted to line
  13. /*
  14. We have network
  15. network access
  16. free pads due
  17. abouse. Please
  18. up for a plan
  19. full network
  20. */
  21. }
  22.  
  23. private static void PrintString(String longString, int lineLegth)
  24. {
  25. String[] mywords = longString.Split(' ');
  26.  
  27. StringBuilder newString = new StringBuilder();
  28. int tempLengh = 0;
  29.  
  30. foreach (string str in mywords)
  31. {
  32. tempLengh += str.Length;
  33.  
  34. if (tempLengh <= lineLegth -1)
  35. {
  36. if (tempLengh == lineLegth -1)
  37. {
  38. newString.Append(str);
  39. }
  40. else
  41. {
  42. newString.Append(str + ' ');
  43. tempLengh = tempLengh + 1;
  44. }
  45.  
  46. }
  47. else
  48. {
  49. newString.Append("\n");
  50. newString.Append(str + ' ');
  51. tempLengh = tempLengh + 1;
  52. tempLengh = 0;
  53. }
  54.  
  55. }
  56.  
  57. Console.Write(newString.ToString());
  58. Console.ReadLine();
  59.  
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement