using System;
using System.Text;
namespace UnityAtoms
{
///
/// Internal extension class for strings.
///
internal static class StringExtensions
{
///
/// Tries to parse a string to an int.
///
/// The string to parse.
/// The default value if not able to parse the provided string.
/// Returns the string parsed to an int. If not able to parse the string, it returns the default value provided to the method.
public static int ToInt(this string str, int def)
{
int num;
return int.TryParse(str, out num) ? num : def;
}
///
/// Repeats the string X amount of times.
///
/// The string to repeat.
/// The number of times to repeat the provided string.
/// The string repeated X amount of times.
public static string Repeat(this string str, int times)
=> times == 1 ? str : new StringBuilder(str.Length * times).Insert(0, str, times).ToString();
///
/// Capitalize the provided string.
///
/// The string to capitalize.
/// A capitalized version of the string provided.
public static string Capitalize(this string str)
{
if (string.IsNullOrEmpty(str))
return string.Empty;
char[] a = str.ToCharArray();
a[0] = char.ToUpper(a[0]);
return new string(a);
}
}
}