using System;
using System.Text;
namespace MediaBrowser.Model.Extensions
{
///
/// Isolating these helpers allow this entire project to be easily converted to Java
///
public static class StringHelper
{
///
/// Equalses the ignore case.
///
/// The STR1.
/// The STR2.
/// true if XXXX, false otherwise.
public static bool EqualsIgnoreCase(string str1, string str2)
{
return string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase);
}
///
/// Replaces the specified STR.
///
/// The STR.
/// The old value.
/// The new value.
/// The comparison.
/// System.String.
public static string Replace(this string str, string oldValue, string newValue, StringComparison comparison)
{
var sb = new StringBuilder();
var previousIndex = 0;
var index = str.IndexOf(oldValue, comparison);
while (index != -1)
{
sb.Append(str.Substring(previousIndex, index - previousIndex));
sb.Append(newValue);
index += oldValue.Length;
previousIndex = index;
index = str.IndexOf(oldValue, index, comparison);
}
sb.Append(str.Substring(previousIndex));
return sb.ToString();
}
public static string FirstToUpper(this string str)
{
return string.IsNullOrEmpty(str) ? "" : str.Substring(0, 1).ToUpper() + str.Substring(1);
}
}
}