Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
how to find and replace '$' in a string
cheeku
I have a string like this: "US $100"
Now I want to check if there is a '$' in the string and replace it with '\$' . How can I do it?
Find more posts tagged with
Comments
hitc
well the problem here is that if you do something like that :
my $test="test $500 test";
$test=~s|\$|\\\$|g;
it will not work because perl will try to interpret $500 as a perl variable.
if you can do that
my $test='test $500 test';
$test=~s|\$|\\\$|g;
it will works since variables between ' ' are not interpreted.
to know if there is a $ :
my $count = ($test =~ tr/$//); # same prob here,if the sentence is between "",it will not work
print $count."\n";
Adam Stoller
What is the context of the source of the string?
- Is this a text or textarea field within a DCT
- Is this a text or textarea field within a WFT instantiation screen?
- Is this a text or textarea field in some other context (what/where)?
- Is this something other than the above (what/where)?
What is the context in which you are trying to modify the string?
- If within a DCT - are you looking to adjust this within the DCT using FormAPI or in a PT using Perl ?
- If this is not within a DCT - where/what/how/when are you trying to adjust it?
The answer hitc provided is true with respect to defining a string within Perl and then processing it with Perl - but if that's not the context which you are talking about, answering the above questions will probably elicit more responses.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
cheeku
I have to do this:
I take the input from the user on a DCT. This input gets saved in the XML of the DCR. I pick up the value of an item from this XML and copy it to another XML . Now if the user enters $ in the input, the value is not correctly copied. How do I escape the $ in the input?
hitc
I just made a little test of my own and had no problem to get a value with a $ and copy it into another dcr.What command are you using to get/copy the value?can you post this part of your code?
cheeku
I apologise for the late reply.Its working fine now. The problem was that I was not escaping the characters(using TeamSite::CGI_lite->escape_html_dat)while copying the string to the xml