Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- public class Test
- {
- public static void Main()
- {
- //Console.WriteLine("Hello");
- string somestring = "We have disbaled network access for free pads due to abouse.";
- PrintString(somestring, 15);
- //Whole sentace to be broken and adjusted to line
- /*
- We have network
- network access
- free pads due
- abouse. Please
- up for a plan
- full network
- */
- }
- private static void PrintString(String longString, int lineLegth)
- {
- String[] mywords = longString.Split(' ');
- StringBuilder newString = new StringBuilder();
- int tempLengh = 0;
- foreach (string str in mywords)
- {
- tempLengh += str.Length;
- if (tempLengh <= lineLegth -1)
- {
- if (tempLengh == lineLegth -1)
- {
- newString.Append(str);
- }
- else
- {
- newString.Append(str + ' ');
- tempLengh = tempLengh + 1;
- }
- }
- else
- {
- newString.Append("\n");
- newString.Append(str + ' ');
- tempLengh = tempLengh + 1;
- tempLengh = 0;
- }
- }
- Console.Write(newString.ToString());
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement