CSharp examples for System:String Start End
Returns true when "search For" starts a position "pos" within "search In" and increments "pos" by the length of search For.
// file, You can obtain one at http://www.apache.org/licenses/ using System.Text.RegularExpressions; using System.Text; using System.Linq; using System.Collections.Generic; using System;//from w w w . j a v a2 s . co m public class Main{ /// <summary> /// Returns true when "searchFor" starts a position "pos" within /// "searchIn" and increments "pos" by the length of searchFor. If /// searchFor does not exist, "pos" will be untouched. /// </summary> /// <param name="searchFor"></param> /// <param name="searchIn"></param> /// <param name="pos"></param> /// <returns></returns> public static bool LookAhead(this string searchIn, string searchFor, ref int pos) { if (searchFor.Length + pos >= searchIn.Length) { return false; } for (var i = 0; i < searchFor.Length; i++) { if (searchFor[i] != searchIn[i + pos]) { return false; } } pos += searchFor.Length; return true; } }