search and break a string?
Hi all, I'm quite new to strings and stuff~ I've checked out the tutorials, but can't help but wonder if there are easier ways to search for certain character through a string of nums and letters?
Can anyone explain this to me? Thank You!
You can use ........
myString = "Where is the King";
result = myString.indexOf("King");
.......to find the word King in a string, and variable "result" will show the number 14 ( as King starts at the 14th character ). If the word king is not present you would get -1
myString.indexOf(substring, [startIndex]) - returns the index number of the substring (if it exists).
yeah, there are a few basic String methods that are always usefull:
if you search for an index of something that doesn't exist, it will return -1, otherwise it will return the int value of where the character is. ie
would return 0
takes 2 params, and will return a new string between those specific indecies.
would return "Hello"
Hope that helps, cheers!
Click Here to Expand Forum to Full Width