StringHelper.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. if (char.IsUpper(str[0]))
  20. {
  21. return str;
  22. }
  23. return string.Create(
  24. str.Length,
  25. str,
  26. (chars, buf) =>
  27. {
  28. chars[0] = char.ToUpperInvariant(buf[0]);
  29. for (int i = 1; i < chars.Length; i++)
  30. {
  31. chars[i] = buf[i];
  32. }
  33. });
  34. }
  35. }
  36. }