Coding Challenges (Replace Method)

Bu bölümde c#'daki metotları kendimce yazmaya çalışıyorum.İlk Replace metoduyla başlamak istedim.Önceden yayınladığım Mors alfabesi dönüştürücüsü programımda Replace metodunu kullanmıştım.Replace kodlarını aşağıda yazdığım metotla değiştirdiğimizde gayet iyi çalışıyor.
Kodlar aşağıda.









1:  #region Değiştir  
2:      public String Degistir(string old, string ne_w, string text)  
3:      {  
4:        string toplam = "",n_toplam="";  
5:        int sayac = 0;  
6:        if (old.Length==1)  
7:        {  
8:        foreach (char item in text)  
9:        {  
10:          if ( Convert.ToString(item)== Convert.ToString(old))  
11:          {  
12:            n_toplam += ne_w;  
13:          }  
14:          else  
15:          {  
16:            n_toplam += item;  
17:          }  
18:        }   
19:         }  
20:        else  
21:        {  
22:          for (int i = 0; i < text.Length; i++)  
23:          {  
24:            if (sayac < old.Length && text[i] == old[sayac])  
25:            {  
26:              toplam += text[i];  
27:              sayac++;  
28:              if (toplam == old)  
29:              {  
30:                n_toplam += ne_w;  
31:                toplam = string.Empty;  
32:                sayac = 0;  
33:              }  
34:            }  
35:            else  
36:            {  
37:              n_toplam += text[i];  
38:            }  
39:          }  
40:        }  
41:        return n_toplam;  
42:      }  
43:      #endregion  
44:    }  
       Durum:Çalışıyor

Yorumlar

Popüler Yayınlar