|
-
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!
-
Senior Member
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).
www.electricbluemonkey.com
-
yeah, there are a few basic String methods that are always usefull:
myString.indexof(someCharacter/string);
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
temp="Hello World";
trace(temp.indexof('H');
would return 0
myString.substring(index1, index2);
takes 2 params, and will return a new string between those specific indecies.
temp="Hello World";
temp2=temp.indexof('H');
temp2=temp.indexof(' ');
trace(temp.substring(temp2, temp3));
would return "Hello"
Hope that helps, cheers!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|