C#置換文字列のサブストリング


using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
  
class Program  
{  
  
    /// <summary>  
    ///   
    /// </summary>  
    /// <param name="str"> </param>  
    /// <param name="toRep"> </param>  
    /// <param name="strRep"> toRep </param>  
    /// <returns> </returns>  
  
    public static string StringReplace(string str, string toRep, string strRep)  
    {  
        StringBuilder sb = new StringBuilder();  
  
        int np = 0, n_ptmp = 0;  
  
        for (; ; )  
        {  
            string str_tmp = str.Substring(np);  
            n_ptmp = str_tmp.IndexOf(toRep);  
  
            if (n_ptmp == -1)  
            {  
                sb.Append(str_tmp);  
                break;  
            }  
            else  
            {  
                sb.Append(str_tmp.Substring(0, n_ptmp)).Append(strRep);  
                np += n_ptmp + toRep.Length;  
            }  
        }  
        return sb.ToString();  
  
    }  
  
  
    /// <summary>  
    ///  :"dwdawdyesdwjdao dyesj yes dwjaodjawiodayes djwaiodyesjijw"  
    /// </summary>  
    /// <param name="args"></param>  
  
    static void Main(string[] args)  
    {  
        string str = Console.ReadLine();  
        str = StringReplace(str, "yes", "no");  
        Console.WriteLine(str);  
        Console.ReadKey();  
    }  
}