How to find substring from string without using indexof method in C#? -


i want find position of substring in string if present without using string method including indexof. tried times failed. tell me how in c#? can use .length operator.

sorry.. thought fun exercise me, so...

spoiler

class program {     static void main(string[] args)     {         string str = "abcdefg";         string substr = "cde";         int index = indexof(str, substr);         console.writeline(index);         console.readline();     }      private static int indexof(string str, string substr)     {         bool match;          (int = 0; < str.length - substr.length + 1; ++i)         {             match = true;             (int j = 0; j < substr.length; ++j)             {                 if (str[i + j] != substr[j])                 {                     match = false;                     break;                 }             }             if (match) return i;         }          return -1;     } } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -