using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using UnityEngine;
namespace MoreMountains.Tools
{
///
/// String helpers
///
public static class MMString
{
///
/// Uppercases the first letter of the parameter string
///
///
///
public static string UppercaseFirst(string s)
{
if (string.IsNullOrEmpty(s))
{
return string.Empty;
}
return char.ToUpper(s[0]) + s.Substring(1);
}
///
/// Returns the length of a rich text, excluding its tags
///
///
///
public static int RichTextLength(string richText)
{
int richTextLength = 0;
bool insideTag = false;
richText = richText.Replace("
", "-");
foreach (char character in richText)
{
if (character == '<')
{
insideTag = true;
continue;
}
else if (character == '>')
{
insideTag = false;
}
else if (!insideTag)
{
richTextLength++;
}
}
return richTextLength;
}
///
/// Elegantly uppercases the first letter of every word in a string
///
///
///
public static string ToTitleCase(this string title)
{
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(title.ToLower());
}
///
/// Removes extra spaces in a string
///
///
///
public static string RemoveExtraSpaces(this string s)
{
return Regex.Replace(s, @"\s+", " ");
}
}
}