473,662 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with a simple problem

However, despite being simple, I can't figure it out (maybe because I'm a
newbie).

I'm trying to replace a string with another string, but it simply is not
working (no error messages, just won't work).

Basically, I have a document and I'd like to every occurrence of '&&1&&'
with 'test'. Eventually the user will specify what '&&1&&' will be replaced
with, but for now I can't get this simple test to work. What am I doing
wrong?

Thanks!

<SCRIPT LANGUAGE="JavaS cript" type="text/javascript">
<!--
var sDocument = new String("This is a &&1&&.");

alert (sDocument);

sDocument.repla ce("&&1&&", "test");
// sDocument.repla ce("&&1&&", txtPrompt.value );

alert (sDocument);

//-->
</SCRIPT>
Jul 20 '05 #1
5 2153
Lee
SteveB said:

However, despite being simple, I can't figure it out (maybe because I'm a
newbie).

I'm trying to replace a string with another string, but it simply is not
working (no error messages, just won't work).


the String.replace( ) method doesn't change the value of the string.
It creates a new string, with the replacement made:

var string1="alpha" ;
var string2=string1 .replace("alph" ,"bet");

Jul 20 '05 #2
Thanks Lee, worked like a charm!

"Lee" <RE************ **@cox.net> wrote in message
news:bn******** *@drn.newsguy.c om...
SteveB said:

However, despite being simple, I can't figure it out (maybe because I'm a
newbie).

I'm trying to replace a string with another string, but it simply is not
working (no error messages, just won't work).


the String.replace( ) method doesn't change the value of the string.
It creates a new string, with the replacement made:

var string1="alpha" ;
var string2=string1 .replace("alph" ,"bet");

Jul 20 '05 #3
One more question if I may. The replace function only seems to replace the
first instance of the string it's looking for. What if there are multiple
instances (for example, more than one &&1&& in my example), how can I
replace them all (keep in mind that I don't know how many there might be)?

Thanks!

"Lee" <RE************ **@cox.net> wrote in message
news:bn******** *@drn.newsguy.c om...
SteveB said:

However, despite being simple, I can't figure it out (maybe because I'm a
newbie).

I'm trying to replace a string with another string, but it simply is not
working (no error messages, just won't work).


the String.replace( ) method doesn't change the value of the string.
It creates a new string, with the replacement made:

var string1="alpha" ;
var string2=string1 .replace("alph" ,"bet");

Jul 20 '05 #4
Lee
SteveB said:

One more question if I may. The replace function only seems to replace the
first instance of the string it's looking for. What if there are multiple
instances (for example, more than one &&1&& in my example), how can I
replace them all (keep in mind that I don't know how many there might be)?


The first argument to replace is more correctly a "regular expression",
rather than a simple string. Regular expressions allow such things
as wildcards and specifying that the replacement should be done
"globally", throughout the string:

string2=string1 .replace(/alph/g,"bet");

The "g" indicates "global" replacement.

Beware that some characters ("^[/", and others) have special
meaning within regular expressions.

Jul 20 '05 #5
Once again... thank you Lee! That did the trick!

"Lee" <RE************ **@cox.net> wrote in message
news:bn******** *@drn.newsguy.c om...
SteveB said:

One more question if I may. The replace function only seems to replace thefirst instance of the string it's looking for. What if there are multiple
instances (for example, more than one &&1&& in my example), how can I
replace them all (keep in mind that I don't know how many there might
be)?
The first argument to replace is more correctly a "regular expression",
rather than a simple string. Regular expressions allow such things
as wildcards and specifying that the replacement should be done
"globally", throughout the string:

string2=string1 .replace(/alph/g,"bet");

The "g" indicates "global" replacement.

Beware that some characters ("^[/", and others) have special
meaning within regular expressions.

Jul 20 '05 #6

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

Similar topics

4
1912
by: C. Smith | last post by:
I am technical advisor for a new group of middle-aged people that want to create a web site for historical information about our local area. They want to scan in a lot of old photos, include information on schools, cemetaries, etc. The web server is NT4 running IIS 4.0. Pages are uploaded via FTP. I personally use Dreamweaver 3, and am learning Dreamweaver MX. I feel that Dreamweaver is too much for this group to learn. I had early...
9
2921
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
3
10640
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
31
2626
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant but it appears to work. using time, i measured it takes .041s to execute, which i admit isnt much. but, the problem is that this procedure will be called many, many times in my project (probably at least a few thousand times, if not more) so...
7
2356
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I have a business layer that I want to use to process any dataentry logic (row focus changes, data...
2
1984
by: Andrew S. Giles | last post by:
OK, Ive run my head into this wall for too long. I need help. I am developing an applicaiton in C# to present a user with a GUI to specify a configurable list of machines that he wants to listen to the output of. Specify a filename to shove all of the data (into Excel), and start the whole thing going. I get that done no problem. The problem comes with the Data. The data is coming from a different application, and I am not 100% sure of...
4
3429
by: Pipo | last post by:
The problem: I create a very simple custom control: public class cLabel : System.Web.UI.WebControls.Label { } I place the cLabel in a user control. When I place the user control on a page I get this exception:
23
2531
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
16
2524
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
25
3104
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of course then the file doesn't get seen by the user. Is there any command that essentially executes the code and then echo's it? something that will take a string like '<body>blah<?php echo 'Hello'; ?></body>' and actually interpret the php
0
8432
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
8857
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...
0
7367
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...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4180
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
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
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.