2019-06-09 10:47:14 -04:00
|
|
|
using System;
|
|
|
|
using System.Text;
|
|
|
|
|
2019-10-01 11:27:22 -04:00
|
|
|
namespace UnityAtoms
|
2019-06-09 10:47:14 -04:00
|
|
|
{
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Internal extension class for strings.
|
|
|
|
/// </summary>
|
2019-06-09 10:47:14 -04:00
|
|
|
internal static class StringExtensions
|
|
|
|
{
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Tries to parse a string to an int.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="str">The string to parse.</param>
|
|
|
|
/// <param name="def">The default value if not able to parse the provided string.</param>
|
|
|
|
/// <returns>Returns the string parsed to an int. If not able to parse the string, it returns the default value provided to the method.</returns>
|
2019-06-09 10:47:14 -04:00
|
|
|
public static int ToInt(this string str, int def)
|
|
|
|
{
|
|
|
|
int num;
|
|
|
|
return int.TryParse(str, out num) ? num : def;
|
|
|
|
}
|
|
|
|
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Repeats the string X amount of times.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="str">The string to repeat.</param>
|
|
|
|
/// <param name="times">The number of times to repeat the provided string.</param>
|
|
|
|
/// <returns>The string repeated X amount of times.</returns>
|
2019-06-09 10:47:14 -04:00
|
|
|
public static string Repeat(this string str, int times)
|
|
|
|
=> times == 1 ? str : new StringBuilder(str.Length * times).Insert(0, str, times).ToString();
|
|
|
|
}
|
|
|
|
}
|