|
-
Senior Member
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.
-
Left-Handed Flash User
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
-
Senior Member
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.
-
Re Member
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.
-
Senior Member
That is what I`m looking for, but is there a version for AS 1, I`m using flash MX ?
-
Senior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|