A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    Jun 2000
    Posts
    108

    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!
    BL

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,150
    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

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    Senior Member
    Join Date
    Nov 2000
    Location
    Malibu
    Posts
    251
    myString.indexOf(substring, [startIndex]) - returns the index number of the substring (if it exists).
    www.electricbluemonkey.com

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    305
    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




Click Here to Expand Forum to Full Width


HTML5 Development Center