aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Extensions/StringHelper.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-02-09 16:58:30 -0500
committerLuke <luke.pulverenti@gmail.com>2015-02-09 16:58:30 -0500
commit4cc3b2f0ccd7c092a4acf72db4903415e175037a (patch)
treef9f90f8665b726253b8b357674f2f141aa43abc9 /MediaBrowser.Model/Extensions/StringHelper.cs
parente7037a9b80843c127712f11430239f8fa3cb4aed (diff)
parent3d7089a7dbabb652730c892206ca050f52f832b1 (diff)
Merge pull request #1005 from MediaBrowser/dev
3.0.5518.0
Diffstat (limited to 'MediaBrowser.Model/Extensions/StringHelper.cs')
-rw-r--r--MediaBrowser.Model/Extensions/StringHelper.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Extensions/StringHelper.cs b/MediaBrowser.Model/Extensions/StringHelper.cs
index 206723467..99bec68a7 100644
--- a/MediaBrowser.Model/Extensions/StringHelper.cs
+++ b/MediaBrowser.Model/Extensions/StringHelper.cs
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
+using System.Text;
using System.Text.RegularExpressions;
namespace MediaBrowser.Model.Extensions
@@ -94,5 +95,35 @@ namespace MediaBrowser.Model.Extensions
{
return new Regex(term).Split(str, limit);
}
+
+ /// <summary>
+ /// Replaces the specified STR.
+ /// </summary>
+ /// <param name="str">The STR.</param>
+ /// <param name="oldValue">The old value.</param>
+ /// <param name="newValue">The new value.</param>
+ /// <param name="comparison">The comparison.</param>
+ /// <returns>System.String.</returns>
+ 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();
+ }
}
}