A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: String replace

  1. #1
    Junior Member
    Join Date
    Oct 2000
    Posts
    22

    String replace

    Hello all

    Is there an actionscript command which will replace part of a string, similar to the str_replace command in php?

    thanks for any help

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Here is a tutorial:

    http://www.flashscript.biz/snippets/...ve_string.html

    just instead of leaving the space blank

    var joined:String = splitted.join("");

    add the new string;
    var joined:String = splitted.join("new string");
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    The Flashman earl223's Avatar
    Join Date
    Sep 2000
    Location
    Marikina City, Philippines
    Posts
    876
    use substr(index,length):
    code:

    myString = "I am good";
    myString = myString.substr(0,5) + "very" + myString.substr(4);

    // myString = "I am very good";

    myString = myString.substr(0,2) + "was" + myString.substr(9);

    // myString = "I was good";


    length is optional. if you don't specifiy the length the substr starting from the index until the end of the string will be returned.
    i eat actionscripts for breakfast

  4. #4
    www.intensewd.com
    Join Date
    Apr 2002
    Location
    Australia
    Posts
    450
    String Replace functions

    That tutorial demonstrates the traditional string replace which is typically split(orig).join(replace), but it also demonstrates case insensitive replacing which doesn't work with the traditional method.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    Los Angeles
    Posts
    86
    Not my script, but it works like a charm:


    myString = myString.replace("[", "<");


    String.prototype.replace = function(pattern, replacement)
    {
    return this.split(pattern).join(replacement);
    }

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