• 19-12-2019, 20:24:33
    #10
    string Join(string sep, string[] arr)
    {
    StringBuilder builder = new StringBuilder();
    foreach (var str in arr)
    {
    builder.Append(str + sep);
    }
    return builder.Length > 0 ? builder.Remove(builder.Length - 1, 1).ToString() : "";
    }
    
    int IndexOf(string str, string search)
    {
    if (search.Length > str.Length)
    return -1;
    for (int i = 0; i < str.Length - search.Length; i++)
    {
    for (int j = 0; j < search.Length; j++)
    {
    if (str[i + j] != search[j])
    break;
    if (j == search.Length - 1)
    return i;
    }
    }
    return -1;
    }
    Vaktim olursa diğerlerini de yazarım hocam veya bunlardan çıkarım yaparak siz uğraşabilirsiniz. Bug vs. olabilir çok detaylı deneyemedim
  • 20-12-2019, 02:18:30
    #11
    Hocam çok teşekkür ederim. Replace(string,string) şeklinde yani old string i new string le değiştircek şekilde yapma şansın var mıdır? En önemlisi replace görünüyor bir türlü yapamadım. Vaktini ayırdığın için minnettarım
  • 21-12-2019, 01:31:07
    #12
    Reveran adlı üyeden alıntı: mesajı görüntüle
    Hocam çok teşekkür ederim. Replace(string,string) şeklinde yani old string i new string le değiştircek şekilde yapma şansın var mıdır? En önemlisi replace görünüyor bir türlü yapamadım. Vaktini ayırdığın için minnettarım
    Önceki yazdığım IndexOf da en sondaysa bulamama sorunu varmış onuda çözdüm. Replace kısmını kendi yazdığım string fonksiyonlarıyla yaptım sıkıntı olmaz sanırım.
     int IndexOf(string str, string search)
    {
    if (search.Length > str.Length)
    return -1;
    for (int i = 0; i < str.Length - search.Length; i++)
    {
    for (int j = 0; j < search.Length; j++)
    {
    if (str[i + j] != search[j])
    break;
    if (j == search.Length - 1)
    return i;
    }
    }
    for (int i = str.Length - search.Length; i < str.Length; i++)
    {
    for (int j = 0; j < search.Length; j++)
    {
    if (str[i + j] != search[j])
    break;
    if (j == search.Length - 1)
    return i;
    }
    }
    return -1;
    }
    string Join(string sep, string[] arr)
    {
    StringBuilder builder = new StringBuilder();
    foreach (var str in arr)
    {
    builder.Append(str + sep);
    }
    return builder.Length > 0 ? builder.Remove(builder.Length - 1, 1).ToString() : "";
    }
    
    static string[] Split(string value, char sep)
    {
    int strt = 0;
    List<string> values = new List<string>();
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < value.Length; i++)
    {
    if (value[i] == sep)
    {
    for (int x = strt; x < i; x++)
    {
    builder.Append(value[x]);
    }
    values.Add(builder.ToString());
    builder.Clear();
    strt = i+1;
    }
    }
    for (int x = strt; x < value.Length; x++)
    {
    builder.Append(value[x]);
    }
    values.Add(builder.ToString());
    return values.ToArray();
    }
    
    static string Replace(string text, string oldVal, string newVal)
    {
    List<string> repList = new List<string>();
    string result;
    if (text == oldVal)
    {
    return text;
    }
    else if (IndexOf(text, oldVal) != -1)
    {
    if (oldVal == " ")
    {
    string[] orjSplit = Split(text, ' ');
    result = Join(newVal, orjSplit);
    return result;
    }
    else
    {
    string[] orjSplit = Split(text, ' ');
    for (int i = 0; i < orjSplit.Length; i++)
    {
    if (orjSplit[i] == oldVal)
    {
    repList.Add(newVal);
    }
    else
    {
    repList.Add(orjSplit[i]);
    }
    }
    result = Join(" ", repList.ToArray());
    return result;
    }
    }
    else
    return text;
    
            }