473,545 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search and Replace for "$" in text

I want to search a textbox and replace any instances of the dollar sign
character. But when I do that it thinks it won't work because it think's I'm
looking to replace something at the end of the line. How do I tell it to
look for literal dollar signs?
Jul 23 '05 #1
10 12080
Terry Olson wrote:
I want to search a textbox and replace any instances of the dollar sign
character. But when I do that it thinks it won't work because it think's
I'm looking to replace something at the end of the line.
What is 'it'?
Some mysterycode we can only guess about?
How do I tell it
to look for literal dollar signs?


2 things that pop into mind:
1) use String.substrin g() in combination with indexOf() and some basic
coding.
2) Or a regular expression which is probably more complex to understand for
starters.
I would advise you to do it with the first option.

Good luck.

Erwin Moller

Jul 23 '05 #2
I am using Regular Expressions, I tried putting just a simple \ in front of
it; as in /\$/g and that seems to work, anyone got a better idea?

"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:41******** *************** @news.xs4all.nl ...
Terry Olson wrote:
I want to search a textbox and replace any instances of the dollar sign
character. But when I do that it thinks it won't work because it think's
I'm looking to replace something at the end of the line.
What is 'it'?
Some mysterycode we can only guess about?
How do I tell it
to look for literal dollar signs?


2 things that pop into mind:
1) use String.substrin g() in combination with indexOf() and some basic
coding.
2) Or a regular expression which is probably more complex to understand

for starters.
I would advise you to do it with the first option.

Good luck.

Erwin Moller

Jul 23 '05 #3
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotma il.com> wrote:
I am using Regular Expressions, I tried putting just a simple \ in front
of it; as in /\$/g and that seems to work, anyone got a better idea?


That *is* how to do it. The only way, in fact. :)

Mike
Please don't top-post.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Michael Winter wrote:
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotma il.com>
wrote:
I am using Regular Expressions, I tried putting just a simple \ in front
of it; as in /\$/g and that seems to work, anyone got a better idea?


That *is* how to do it. The only way, in fact. :)

Mike
Please don't top-post.


This works fine for me:

$str1 = '$Hello! All the dollars $ should $ be replaced by $ **';
$str2 = ereg_replace ( '\$', '**', $str1);

echo "str1= $str1<br>";
echo "str2= $str2<br>";
Jul 23 '05 #5
Erwin Moller wrote:
Michael Winter wrote:
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotma il.com>
wrote:
I am using Regular Expressions, I tried putting just a simple \ in front
of it; as in /\$/g and that seems to work, anyone got a better idea?


That *is* how to do it. The only way, in fact. :)

Mike
Please don't top-post.


This works fine for me:

$str1 = '$Hello! All the dollars $ should $ be replaced by $ **';
$str2 = ereg_replace ( '\$', '**', $str1);

echo "str1= $str1<br>";
echo "str2= $str2<br>";


Oops, sorry, that was PHP of course. :-)
Excuse me.
Jul 23 '05 #6
On Tue, 07 Sep 2004 12:30:30 +0200, Erwin Moller
<si************ *************** *************** @spamyourself.c om> wrote:
Michael Winter wrote:
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotma il.com>
wrote:
I am using Regular Expressions, I tried putting just a simple \ in
front of it; as in /\$/g and that seems to work, anyone got a better
idea?
That *is* how to do it. The only way, in fact. :)


[snip]
$str1 = '$Hello! All the dollars $ should $ be replaced by $ **';
$str2 = ereg_replace ( '\$', '**', $str1);


If converted to Javascript, you don't need the backslash with the string
argument form of the replace method. In that instance, it's a simple
string comparison. If you are using a regular expression, then the
backslash is necessary to ensure the ampersand isn't interpreted as a
special character. This latter case is what I was referring to. So
initially, your two options are:

var str = '$Hello! All the dollars $ should $ be replaced by $ **',
res;

res = str.replace('$' , '**');

or

res = str.replace(/\$/, '**');

However, both of these should only replace the first instance of an
ampersand. If all occurances need to be replaced, you have to use regular
expression the OP presented:

res = str.replace(/\$/g, '**');

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7
Michael Winter wrote on 07 sep 2004 in comp.lang.javas cript:
res = str.replace(/\$/, '**');

However, both of these should only replace the first instance of an
ampersand. If all occurances need to be replaced, you have to use
regular expression the OP presented:


I know the $ is devaluating, but has it become an & ?

;-}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #8
On 07 Sep 2004 13:10:09 GMT, Evertjan. <ex************ **@interxnl.net >
wrote:
Michael Winter wrote on 07 sep 2004 in comp.lang.javas cript:
res = str.replace(/\$/, '**');

However, both of these should only replace the first instance of an
ampersand. If all occurances need to be replaced, you have to use
regular expression the OP presented:


I know the $ is devaluating, but has it become an & ?

;-}


:P

Hmm. Yes, I meant a dollar symbol rather than an ampersand.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #9
JRS: In article <opsdx7e9d6x13k vk@atlantis>, dated Tue, 7 Sep 2004
08:33:02, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
ueyonder.co.inv alid> posted :
On Tue, 07 Sep 2004 08:27:11 GMT, Terry Olson <tw******@hotma il.com> wrote:
I am using Regular Expressions, I tried putting just a simple \ in front
of it; as in /\$/g and that seems to work, anyone got a better idea?


That *is* how to do it. The only way, in fact. :)


x = "34$56".replace (/\x24/, '#')
x = "34$56".replace (/\044/, '#')
x = "34$56".replace (/\u0024/, '#')
x = "34$56".replace (/[^\000-#%-\377]/, '#')

all give me "34#56".

By "only", you must mean "proper" or "best" rather than "unique".

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links;
some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3717
by: andreas kirschner | last post by:
hello regexp developers, how can i replace text outside a html syntax by using reg exps in php? I mean i have a text like <h3>heading</h3> <p>text</p> <table> <tr> <td>cell1</td>
2
13285
by: Svennglenn | last post by:
I'm having problems replacing text in a unicode string. Here's the code: # -*- coding: cp1252 -*- titel = unicode("ä", "iso-8859-1") print titel print type(titel)
1
11076
by: michael | last post by:
What methods (eg. CSS/Javascript) are there to dynamically replace text other than dynamically changing form text field values? I don't mean color styles and fonts etc., but actual text content itself. Any one has pointers to example pages/tutorials?
36
72022
by: spence | last post by:
Hi All How do I make it so that when a user clicks in a search text field, the default entry (in this case "Search") is removed automatically - they are then faced with a blank search box and can type straight away Thanks in advance
3
2047
by: Andla Rand | last post by:
Hi, I would appreciate some directions on how to replace text as server controls. I'm currently reading text from a database and would like to build server logic based on specific information retrieved from the server. Here is some sample code that I'm currently playing with: string repl=spn.InnerHtml;
5
4749
by: Casey | last post by:
Hello, Can someone give me specific code to replace text on a page using server side javascript? I need to use server-side because I need the output to be recognized in the final HTML so that google can index it. Here is a specific example of what I want to do: <div id=SomeText> Here is some text. I went to the baseball game </div>
1
3149
by: shantibhushan | last post by:
Hi buddy I have to highlight search text from search results as it is in google or alibaba.com. e.g. if I input paper as a searchtext in search results paper word should be highlighted. as it isin google help. some one help me please. I am working in asp.net2.0 using c# Regards,
0
946
by: Ivica Muruzovic | last post by:
How can I use previous typed search text in google search box or any other web browser. I have combobox and want to fill him with that previous typed search text on local machine
1
1255
by: fosforito | last post by:
How can you replace text in batch mode (that is, a large text with many entries of that kind)? For example: Look for "http://microsoft.com/serverads/" and replace it for "http://microsoft.com/adsservice/" Thanks.
4
6818
by: sangam56 | last post by:
Hi all. I have an iframe in an asp.net web page (Display.aspx). <iframe id="iframe1" runat="server" src="temp/test.html"></iframe> Now I need to highlight a search text, say 'test' in the Display.aspx page. The source of iframe is dynamically assigned and search text is also changeable. This means I am dealing with dynamic search text and...
0
7398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.