jeudi 6 mars 2014

using indexOf method to give all instances


Vote count:

0




So I was wondering how you would use indexOf() or related method to return all instances of a character occurring in a string. What I have right now does the following:



  • I have a word "sneest"

  • I enter e and it displays 2. I want it to display 2,3




yshavit

10.2k

asked 3 mins ago


1 Answer



Vote count:

0





int pos = str.indexOf("foo"):
while (pos >= 0) {
//do something
pos = str.indexOf("foo", pos + 1):
}


answered 13 secs ago





Aucun commentaire:

Enregistrer un commentaire