A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: string replace in flash

Hybrid View

  1. #1
    Senior Member vucjak's Avatar
    Join Date
    Mar 2002
    Location
    BanjaLuka, RS, Bosnia
    Posts
    306

    string replace in flash

    How to replace loaded var. value like this one
    "test1" into "test2" ?

    Let me explain this a little bit, when I load variable I get this value
    "test1"
    I need something that`ll replace it to this variable value
    "test2"
    Last edited by vucjak; 09-24-2004 at 07:25 PM.

  2. #2
    Left-Handed Flash User mickbrit55's Avatar
    Join Date
    Nov 2003
    Location
    NJ USA
    Posts
    1,375
    Hiya

    Under what conditions do you want to change the variable? You could do this :

    code:
    if (x == "test1") {
    x = "test2"
    }



    ... which is pretty pointless. Depends on what you want to do with test1 and test2 and when you want it to change.

    Mick

  3. #3
    Senior Member vucjak's Avatar
    Join Date
    Mar 2002
    Location
    BanjaLuka, RS, Bosnia
    Posts
    306
    well that is not what I had in mind.. see
    if I have one string with this value
    "mystringtest1mystring"
    So I need script that will work like convertor of every string with "test1" as a part of it`s value.
    so my result after conversion will be
    "mystringtest2mystring"

    I hope you know what i mean, thanks!
    Last edited by vucjak; 09-27-2004 at 12:45 AM.

  4. #4
    Re Member websam's Avatar
    Join Date
    Jul 2000
    Location
    Australia (VIC)
    Posts
    660
    If you familiar with AS2.0. Build a customized class as it is very useful in your future project:

    code:

    class SwapChar {
    public function SwapChar (){}
    public function swap(s:String,findS:String,replaceS:String):String {
    return s.split(findS).join(replaceS);
    }
    }



    You can make this class as extend class to String Object.


    otherwise, make it into a function:

    code:

    function swap(s,findS,replaceS){
    return s.split(findS).join(replaceS);
    }



    swap(s,findS,replaceS)
    s = string to be modified
    findS = string bloack to be identified
    replaceS = string to replace located string block (findS)

    In you case
    swap("mystringtest1mystring", "test1", "test2");


    This serves exactly the same as string.replace() in VB
    Last edited by websam; 09-27-2004 at 02:06 AM.

  5. #5
    Senior Member vucjak's Avatar
    Join Date
    Mar 2002
    Location
    BanjaLuka, RS, Bosnia
    Posts
    306
    That is what I`m looking for, but is there a version for AS 1, I`m using flash MX ?

  6. #6
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    The swap function, described above, will work in AS 1.

    - Jim

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