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

前端 未结 7 1442
时光取名叫无心
时光取名叫无心 2020-12-20 05:44

I want to find the position of a substring in a string if present without using any string method including indexof. I tried so much times but failed. Will anybody tell me h

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 06:18

    Try this:

    public static string BetweenOf(string ActualStr, string StrFirst, string StrLast)  
    { 
        return ActualStr.Substring(ActualStr.IndexOf(StrFirst) + StrFirst.Length,
              (ActualStr.Substring(ActualStr.IndexOf(StrFirst))).IndexOf(StrLast) + StrLast.Length);    
    } 
    

提交回复
热议问题