---
title: "Fastest C# Case Insenstive String Replace"
author: "winyee"
date: "2010-06-06T11:15:07Z"
tags: []
categories: ["编程语言"]
slug: "fastest-c-case-insenstive-string-replace"
draft: false
lastmod: "2010-06-06T11:15:07Z"
id: 685049
url: "https://winyee.iteye.com/blog/685049"
---

private static string ReplaceEx(string original, 
                    string pattern, string replacement)
{
    int count, position0, position1;
    count = position0 = position1 = 0;
    string upperString = original.ToUpper();
    string upperPattern = pattern.ToUpper();
    int inc = (original.Length/pattern.Length) * 
              (replacement.Length-pattern.Length);
    char  chars = new char;
    while( (position1 = upperString.IndexOf(upperPattern, 
                                      position0)) != -1 )
    {
        for ( int i=position0 ; i < position1 ; ++i )
            chars = original*;
        for ( int i=0 ; i < replacement.Length ; ++i )
            chars = replacement*;
        position0 = position1+pattern.Length;
    }
    if ( position0 == 0 ) return original;
    for ( int i=position0 ; i < original.Length ; ++i )
        chars = original*;
    return new string(chars, 0, count);
}

http://www.codeproject.com/KB/string/fastestcscaseinsstringrep.aspx