uccjshrimpton

C# Basic String Manipulation

Nov 11th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. string forename, surname;
  2. forename = "James";
  3. surname = "Shrimpton";
  4.  
  5. //Allows you to format a string in a convenient way
  6. Console.WriteLine("FORENAME:{0} SURNAME:{1}", forename, surname);
  7.  
  8. //Outputs the length of a string
  9. Console.WriteLine(forename.Length);
  10.  
  11. //Outputs the characters in the 5th position (index from 0)
  12. Console.WriteLine(forename[4]);
  13.  
  14. //The most Pythonic way to reverse a string
  15. string reverse = string.Join("",surname.ToCharArray().Reverse().ToArray());
  16. Console.WriteLine(reverse);
  17.  
  18. //Converts a string to upper and lower case
  19. Console.WriteLine(reverse.ToUpper());
  20. Console.WriteLine(reverse.ToLower());
  21.  
  22. //Single line way of emulating 'String.Title()'
  23. reverse = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(reverse.ToLower());
  24. Console.WriteLine(reverse);
  25.  
  26. Console.ReadLine();
Advertisement
Add Comment
Please, Sign In to add comment