nsmutablestring - Objective C - Extract substring by finding first and second occurrence of a character -


i trying port android app ios. need extract string present between first , second occurrence of single quote ' character.

for example, javascript:popupwindow7('news_details.asp?slno=2029',620,300,100,100,'yes'), need extract news_details.asp?slno=2029.

in java, did this:

string inputurl = "javascript:popupwindow7('news_details.asp?slno=2029',620,300,100,100,'yes')"; stringbuilder url = new stringbuilder(); url.append(inputurl.substring(inputurl.indexof('\'')+1,                  inputurl.indexof('\'',inputurl.indexof('\'')+1))); 

i can't find method similar indexof in objective c, did following:

nsuinteger length =0; nsmutablestring* url;  nsstring* urltodecode = @"javascript:popupwindow7('news_details.asp?slno=2029',620,300,100,100,'yes')";  (nsinteger i=[urltodecode rangeofstring:@"\'"].location +1; i<urltodecode.length; i++) {      if([urltodecode characteratindex:i]== '\'')     {         length = i;         break;     } }  nsrange range = nsmakerange([urltodecode rangeofstring:@"\'"].location +1, length);  [url appendstring:[urltodecode substringwithrange:range]]; 

what doing wrong?

the problem code range's length counted location zero, not range's location. range's length not index @ end of range, distance between range's starting location , end.

how simpler alternative:

nsarray *components = [urltodecode componentsseparatedbystring:@"'"]; if (components.count > 1) {     nsstring *substring = components[1]; } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -