Strings
-
Need to devise code for the following problem String Line Character CharSelect Integer Begin Returns the index of the first occurrence of the character CharSelect in string Line starting from index Begin If Line has value “Most people find this hard” and if CharSelect has value ‘t’ and Begin has value 5 then 18 is returned. Any help much appreciated. Bill
-
Need to devise code for the following problem String Line Character CharSelect Integer Begin Returns the index of the first occurrence of the character CharSelect in string Line starting from index Begin If Line has value “Most people find this hard” and if CharSelect has value ‘t’ and Begin has value 5 then 18 is returned. Any help much appreciated. Bill
String *Line = S"Most people find this hard"; String *char = S"t"; Int16 iBegin = 5; //Substring Line to all characters from iBegin on //Find index of 'char' in the substring Int16 iIndex = Line->Substring(iBegin)->IndexOf( char ); //Index total by adding whatever iIndex found with iBegin Console::Write( iIndex + iBegin ); *** That's probably the most simple way. There are some other ways (using IndexOf/IndexOfAny, or some other string functions that I don't recall at the moment) that may also work for finding a character within a specific range. Cyric