473,698 Members | 2,221 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 12111
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
3720
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
13293
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
11083
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
72054
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
2052
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
4768
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
3153
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
950
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
1265
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
6830
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 html page. Please suggest me how could I highlight the search texts in the iframe placed in the...
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8885
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7708
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4358
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.