Replace Once : String Replace « Data Types « C# / C Sharp






Replace Once

         
namespace Qxado.DataAccess.Implementation.Util
{
    using System.Text;

    public static class StringHelper
    {
        public static string ReplaceOnce(string template, string placeholder, string replacement) {
            var loc = template.IndexOf(placeholder);
            return loc < 0 ? template : new StringBuilder(template.Substring(0, loc))
                                            .Append(replacement)
                                            .Append(template.Substring(loc + placeholder.Length))
                                            .ToString();
        }
    }
}

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Replace char inside a string
2.use the Insert(), Remove(), and Replace() methods to modify strings
3.String reverse and replaceString reverse and replace
4.Inserting, replacing, and removingInserting, replacing, and removing
5.String insert and outputString insert and output
6.remove any of a set of chars from a given string.
7.Replaces the specified string to replace.
8.Replaces the new lines in a string with the given replacement characters.