Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Display
- {
- //gets user input and max number of characters the user wants on each line
- public static void Write(string input,int maxChar = 50)
- {
- //variables
- string[] string_array = input.Split(" ");
- int number_of_char = 0;
- int i = 0;
- //runs through each word in the big string
- foreach (string str in string_array)
- {
- //acounts for every character in each word including spaces
- number_of_char += str.Length + 1;
- //if the number of characters exceedes max character limit a new line is created
- if (number_of_char >= maxChar)
- {
- if (i<string_array.Length)
- {
- Console.Write($"\n{str} ");
- //resets char count for new line
- number_of_char = 0;
- }
- }
- //continues printing normaly if the character limit for that line is not reached
- else
- {
- Console.Write(str+" ");
- }
- i++;
- }
- }
- public static void WriteLine(string input, int maxChar = 50)
- {
- string[] string_array = input.Split(" ");
- int number_of_char = 0;
- foreach (string str in string_array)
- {
- number_of_char += str.Length + 1;
- if (number_of_char >= maxChar)
- {
- Console.Write($"\n{str} ");
- number_of_char = 0;
- }
- else
- {
- Console.Write(str + " ");
- }
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement