# Remove comma?

**URL:** <https://forum.kirupa.com/t/remove-comma/261527>\
**Category:** Uncategorized\
**Created:** [May 28, 2008, 2:51pm UTC](https://forum.kirupa.com/t/remove-comma/261527 "2008-05-28T14:51:11Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![hroth](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@hroth](https://forum.kirupa.com/u/hroth)\
**Post date:** [May 28, 2008, 2:51pm UTC](https://forum.kirupa.com/t/remove-comma/261527/1 "2008-05-28T14:51:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Digitalosophy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalosophy/32/1114_2.png) [@Digitalosophy](https://forum.kirupa.com/u/Digitalosophy)\
**Post date:** [May 28, 2008, 4:33pm UTC](https://forum.kirupa.com/t/remove-comma/261527/2 "2008-05-28T16:33:01Z")

</div>

You need to do a search and replace. You can search for more threads but I found this one pretty easy to use.

> **[search for word and replace it with different words](https://www.kirupa.com/forum/showthread.php?t=241927&highlight=search+replace)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

---

<div class="post-metadata">

**Author:** ![shaftoe](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shaftoe](https://forum.kirupa.com/u/shaftoe)\
**Post date:** [May 28, 2008, 4:35pm UTC](https://forum.kirupa.com/t/remove-comma/261527/3 "2008-05-28T16:35:06Z")

</div>

[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 \_

---

<div class="post-metadata">

**Author:** ![Digitalosophy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalosophy/32/1114_2.png) [@Digitalosophy](https://forum.kirupa.com/u/Digitalosophy)\
**Post date:** [May 28, 2008, 4:43pm UTC](https://forum.kirupa.com/t/remove-comma/261527/4 "2008-05-28T16:43:29Z")

</div>

^ Only available in AS 3 though.

---

<div class="post-metadata">

**Author:** ![shaftoe](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shaftoe](https://forum.kirupa.com/u/shaftoe)\
**Post date:** [May 28, 2008, 4:45pm UTC](https://forum.kirupa.com/t/remove-comma/261527/5 "2008-05-28T16:45:33Z")

</div>

^ Oops yeah!

---

<div class="post-metadata">

**Author:** ![hroth](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@hroth](https://forum.kirupa.com/u/hroth)\
**Post date:** [May 28, 2008, 5:21pm UTC](https://forum.kirupa.com/t/remove-comma/261527/6 "2008-05-28T17:21:41Z")

</div>

AS3 is fine… but I ran this error:  
The class or interface ‘RegExp’ could not be loaded.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 28, 2008, 5:50pm UTC](https://forum.kirupa.com/t/remove-comma/261527/7 "2008-05-28T17:50:42Z")

</div>

You have to import it first 🙂

---

<div class="post-metadata">

**Author:** ![hroth](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@hroth](https://forum.kirupa.com/u/hroth)\
**Post date:** [May 28, 2008, 6:08pm UTC](https://forum.kirupa.com/t/remove-comma/261527/8 "2008-05-28T18:08:30Z")

</div>

> [@sekasi;2332483](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 28, 2008, 6:35pm UTC](https://forum.kirupa.com/t/remove-comma/261527/9 "2008-05-28T18:35:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hroth](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@hroth](https://forum.kirupa.com/u/hroth)\
**Post date:** [May 28, 2008, 6:47pm UTC](https://forum.kirupa.com/t/remove-comma/261527/10 "2008-05-28T18:47:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Digitalosophy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalosophy/32/1114_2.png) [@Digitalosophy](https://forum.kirupa.com/u/Digitalosophy)\
**Post date:** [May 28, 2008, 6:50pm UTC](https://forum.kirupa.com/t/remove-comma/261527/11 "2008-05-28T18:50:26Z")

</div>

If you need an AS 2 solution look at the link I provided, it’s cut and dry.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 28, 2008, 6:53pm UTC](https://forum.kirupa.com/t/remove-comma/261527/12 "2008-05-28T18:53:49Z")

</div>

hehe.

No problem, but try to migrate to AS3. The faster the better; )

AS2.0 version;

```auto

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,",","_"));

```

---

<div class="post-metadata">

**Author:** ![hroth](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@hroth](https://forum.kirupa.com/u/hroth)\
**Post date:** [May 28, 2008, 7:56pm UTC](https://forum.kirupa.com/t/remove-comma/261527/13 "2008-05-28T19:56:20Z")

</div>

(the variable “style\_shirt” is “shirt,colour”)

```auto
 
 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

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 28, 2008, 8:20pm UTC](https://forum.kirupa.com/t/remove-comma/261527/14 "2008-05-28T20:20:56Z")

</div>

```auto

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…

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 28, 2008, 8:22pm UTC](https://forum.kirupa.com/t/remove-comma/261527/15 "2008-05-28T20:22:04Z")

</div>

> and when I “trace(sammy);” it outputs: shirt,colour

I’d wager that style\_shirt is an array, not a string…

---

<div class="post-metadata">

**Author:** ![hroth](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@hroth](https://forum.kirupa.com/u/hroth)\
**Post date:** [May 30, 2008, 2:04pm UTC](https://forum.kirupa.com/t/remove-comma/261527/16 "2008-05-30T14:04:57Z")

</div>

[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]
