Advertisement
Guest User

TA, C# - Part2, Strings and Text Processing, #6

a guest
Jan 21st, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. /* #6. Write a program that reads from the console a string of maximum 20 characters. If the length of the string is less than 20, the rest of the characters should be filled with '*'. Print the result string into the console. */
  8.  
  9. class FillTo20WithStars
  10. {
  11.     static void Main()
  12.     {
  13.         Console.WriteLine("Please enter below a string with maximum of 20 characters:");
  14.         string inputString = Console.ReadLine();
  15.  
  16.         StringBuilder sb = new StringBuilder();
  17.         for (int i = 0; i < inputString.Length; i++)
  18.         { sb.Append(inputString[i]); }
  19.         for (int j = 1; j < 20 - inputString.Length + 1; j++)
  20.         { sb.Append('*'); }
  21.         string outputString = sb.ToString();
  22.  
  23.         Console.WriteLine("The resulting string is:");
  24.         Console.WriteLine(outputString);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement