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