StringHelper.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. namespace MediaBrowser.Model.Extensions
  2. {
  3. /// <summary>
  4. /// Helper methods for manipulating strings.
  5. /// </summary>
  6. public static class StringHelper
  7. {
  8. /// <summary>
  9. /// Returns the string with the first character as uppercase.
  10. /// </summary>
  11. /// <param name="str">The input string.</param>
  12. /// <returns>The string with the first character as uppercase.</returns>
  13. public static string FirstToUpper(string str)
  14. {
  15. if (str.Length == 0)
  16. {
  17. return str;
  18. }
  19. // We check IsLower instead of IsUpper because both return false for non-letters
  20. if (!char.IsLower(str[0]))
  21. {
  22. return str;
  23. }
  24. return string.Create(
  25. str.Length,
  26. str,
  27. (chars, buf) =>
  28. {
  29. chars[0] = char.ToUpperInvariant(buf[0]);
  30. for (int i = 1; i < chars.Length; i++)
  31. {
  32. chars[i] = buf[i];
  33. }
  34. });
  35. }
  36. }
  37. }