wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes changing $ to a different character in javascript variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "changing $ to a different character in javascript variable" Watch "changing $ to a different character in javascript variable" New topic
Author

changing $ to a different character in javascript variable

Rohit Sajan
Ranch Hand

Joined: Jun 15, 2006
Posts: 34
In javascript i want to replace $ with another character ; , but when i used the normal replace moethod it's not happening. Is $ having any specific meaning in regular expression. My requirement is replace sim$san with sim;san
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

$ means the end of the line. So you must escape it using '\$'


[My Blog]
All roads lead to JavaRanch
Ashish K Sharma
Ranch Hand

Joined: Aug 22, 2006
Posts: 31
Hi,
I have wrote a sample function and it returns perfectly fine value

js code::
********************
var inParam = "sim$sin";
var outParam = inParam.replace("$",";");
alert(outParam);
***********************

Do let me know if you are trying something else or you have some other requirement.
Rohit Sajan
Ranch Hand

Joined: Jun 15, 2006
Posts: 34
forgot to mention that $ sign occurance comes multipe times in the variable. If it is only one time then simple replace comes.

eg: sim$san$sin$sam should come like this sim;san;sin;sam

I tried like this finalVals=finalVals.replace(/$/g,';');
but not working. For other characters it works fine
[ August 25, 2006: Message edited by: Saju Pappachen ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10240
    
168

As Satou kurinosuke already mentioned, $ is a special character so you will have to use \$ to do the replacements. Here's the code:




[My Blog] [JavaRanch Journal]
Rohit Sajan
Ranch Hand

Joined: Jun 15, 2006
Posts: 34
yes jaikiran I tried the option suggested by both of you. Still it is not changing the $ characters
Ashish K Sharma
Ranch Hand

Joined: Aug 22, 2006
Posts: 31
hi,
Can you please send what code you are trying and in which format/ which field you what to populate the replaced string?That would be helpful to identify.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changing $ to a different character in javascript variable