Tinkr2/4.2/AphelionCore/AphelionCore/Helpers/Strings.cs
/// <summary>
/// Replaces all instances of a string in a string with a new value
/// </summary>
/// <param name="source">String to be modified</param>
/// <param name="toFind">String to find within the source</param>
/// <param name="replaceWith">New value to replace all ToFind instances with</param>
/// <returns>Returns the modified string</returns>
Replaces all instances of a string in a string with a new value
Replaces all instances of a string in a string with a new value
public static string Replace(string source, string toFind, string replaceWith)
      {
         int iStart = 0;
         if (source == string.Empty || source == null || toFind == string.Empty || toFind == null)
         {
            return source;
         }
         while (true)
         {
            int i = source.IndexOf(toFind, iStart);
            if (i < 0) break;
            if (i > 0)
            {
               source = source.Substring(0, i) + replaceWith + source.Substring(i + toFind.Length);
            }
            else
            {
               source = replaceWith + source.Substring(i + toFind.Length);
            }
            iStart = i + replaceWith.Length;
         }
         return source;
      }
public static string Replace ( string source , string toFind , string replaceWith ) { int iStart = 0 ; if ( source == string . Empty || source == null || toFind == string . Empty || toFind == null ) { return source ; } while ( true ) { int i = source . IndexOf ( toFind , iStart ) ; if ( i < 0 ) break ; if ( i > 0 ) { source = source . Substring ( 0 , i ) + replaceWith + source . Substring ( i + toFind . Length ) ; } else { source = replaceWith + source . Substring ( i + toFind . Length ) ; } iStart = i + replaceWith . Length ; } return source ; }
Replaces all instances of a string in a string with a new value
Replaces all instances of a string in a string with a new value
Returns the modified string
Returns the modified string
source
string
String to be modified
String to be modified
toFind
string
String to find within the source
String to find within the source
replaceWith
string
New value to replace all ToFind instances with
New value to replace all ToFind instances with