jellyfin/MediaBrowser.Model/Extensions/StringHelper.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2018-12-27 16:27:57 -07:00
namespace MediaBrowser.Model.Extensions
{
/// <summary>
2020-01-09 09:07:13 -07:00
/// Helper methods for manipulating strings.
2018-12-27 16:27:57 -07:00
/// </summary>
public static class StringHelper
{
/// <summary>
2020-01-16 15:22:42 -07:00
/// Returns the string with the first character as uppercase.
2018-12-27 16:27:57 -07:00
/// </summary>
2020-01-09 09:07:13 -07:00
/// <param name="str">The input string.</param>
/// <returns>The string with the first character inheritdoc uppercase.</returns>
public static string FirstToUpper(string str)
2018-12-27 16:27:57 -07:00
{
2020-01-09 09:07:13 -07:00
if (string.IsNullOrEmpty(str))
2018-12-27 16:27:57 -07:00
{
2020-01-09 09:07:13 -07:00
return string.Empty;
2018-12-27 16:27:57 -07:00
}
2020-01-09 09:07:13 -07:00
if (char.IsUpper(str[0]))
{
return str;
}
2018-12-27 16:27:57 -07:00
2020-01-09 09:07:13 -07:00
return string.Create(
str.Length,
str,
(chars, buf) =>
{
chars[0] = char.ToUpperInvariant(buf[0]);
for (int i = 1; i<chars.Length; i++)
{
chars[i] = buf[i];
}
});
2018-12-27 16:27:57 -07:00
}
}
}