Hi there,
I have a couple variables that I’ve concatenated.
The output is: variable1,variable2
I would like to replace the comma with an underscore.
so the output is: variable1_variable2
thanks in advance~!
-hroth
Hi there,
I have a couple variables that I’ve concatenated.
The output is: variable1,variable2
I would like to replace the comma with an underscore.
so the output is: variable1_variable2
thanks in advance~!
-hroth
You need to do a search and replace. You can search for more threads but I found this one pretty easy to use.
[quote=hroth;2332360]Hi there,
I have a couple variables that I’ve concatenated.
The output is: variable1,variable2
I would like to replace the comma with an underscore.
so the output is: variable1_variable2
thanks in advance~!
-hroth[/quote]
var pattern:RegExp = /[ ',-()]/gi;
var newstring:String = oldstring.replace(pattern,"_");
will replace ’ , - ( and ) with _
^ Only available in AS 3 though.
^ Oops yeah!
AS3 is fine… but I ran this error:
The class or interface ‘RegExp’ could not be loaded.
You have to import it first
I’ve never imported such a thing… I’m soooo old school
I’ve been digging in the help and I’ve tried a few things…
… but I’m not sure what to do.
Do I need to make an .as file? and import it? Is there a library of them?
I would appreciate a bit of a step by step…
I SWEAR I’m trying to do it myself and reading all the help stuff!
I’m not just lazy
-hroth
Actually come to think about it I don’t think you need to import Regular expressions.
Are you exporting to AS3.0, Flash9 in your export settings?
I checked and I was exporting to AS2.
I switched it to AS3 and exported… oh my…
It was flickering like MAD! I have WAY too many "old school"
things. I’d have to go through and try to update all my scripts!
I still don’t know how to do some things from my flash 5 days in
modern flash… I’ve been too slow in REALLY updating…
hmm… I don’t really have the time to risk this learning curve thing.
I might be better off in this instance in trying to find a solution
that works in AS2… sigh It’s hard to re-learn on a tight deadline
when one knows a way that does work you know?..
I’m still a _root.variable addict… I have Text field variable names…
oh my… I’m not sure what to do at this point… hmm…
do you want to look at a copy of my file?
If you need an AS 2 solution look at the link I provided, it’s cut and dry.
hehe.
No problem, but try to migrate to AS3. The faster the better; )
AS2.0 version;
function stringReplace(orgstring:String, target:String, subst:String):String {
return orgstring.split(target).join(subst);
}
var orgstring:String = "hi, I, am, a, soldier";
trace(stringReplace(orgstring,",","_"));
(the variable “style_shirt” is “shirt,colour”)
var sammy= style_shirt;
function stringReplace(orgstring:String, target:String, subst:String):String {
return orgstring.split(target).join(subst);
}
var orgstring:String = sammy;
trace(stringReplace(orgstring,",","_"));
}
this outputs : "Undefined"
I can’t seem to get this variable to come out as: “shirt_colour”
can I have a variable where "var orgstring:String = sammy;"
and when I “trace(sammy);” it outputs: shirt,colour
I think I have to do something to the variable so it will run or something?
The variable is there… and it works if I put anything but a variable…
-sadly - still struggling
var style_shirt:String = "hej,ho";
var sammy:String = style_shirt;
function stringReplace(orgstring:String, target:String, subst:String):String {
return orgstring.split(target).join(subst);
}
trace(stringReplace(sammy,",","_"));
Works fine, problem is probably that something isn’t a proper string…
and when I “trace(sammy);” it outputs: shirt,colour
I’d wager that style_shirt is an array, not a string…
[COLOR=black]that was EXACTLY the problem. I was using an array while doing a concat.[/COLOR]
[COLOR=black](which was totally unnecessary) I stepped back to: variable+"_"+variable.[/COLOR]
[COLOR=black]Which got rid of the array… which had given me the comma in the first place… [/COLOR]
[COLOR=black]…so the whole thing was me going about something simple the wrong way…[/COLOR]
[COLOR=black]Thanks for all the help! All works![/COLOR]
[COLOR=black]-hroth[/COLOR]
:: Copyright KIRUPA 2024 //--