473,698 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple Replace in a string

JS
Is it possible to do multiple replaces in a string?

Example: I'm trying to replace all of the spaces with "%20" and "#" with
"%23", etc. I also need to replace the "?", "!", " ' ", etc.

I know I can do this with:
thisString.Repl ace(" ", "%20")
thisString.Repl ace("#", "%23")

But, I'm trying to find a way to do this one line of code.

Any Ideas?

TIA

JS
Nov 15 '05 #1
2 2797
Check Regex.Replace

HTH
Alex

"JS" <no*****@northe re.com> wrote in message
news:re******** ************@co mcast.com...
Is it possible to do multiple replaces in a string?

Example: I'm trying to replace all of the spaces with "%20" and "#" with
"%23", etc. I also need to replace the "?", "!", " ' ", etc.

I know I can do this with:
thisString.Repl ace(" ", "%20")
thisString.Repl ace("#", "%23")

But, I'm trying to find a way to do this one line of code.

Any Ideas?

TIA

JS

Nov 15 '05 #2
JS,
Have you tried:
thisString.Repl ace(" ", "%20")
thisString.Repl ace("#", "%23")
thisString = thisString.Repl ace(" ", "%20").Replace( "#", "%23").
Example: I'm trying to replace all of the spaces with "%20" and "#" with
"%23", etc. I also need to replace the "?", "!", " ' ", etc. Although you may be approaching enough replacements that I would consider
using a StringBuilder instead. I would encapsulate the use of the
StringBuilder into a function, or possibly even a class.

Hope this helps
Jay

"JS" <no*****@northe re.com> wrote in message
news:re******** ************@co mcast.com... Is it possible to do multiple replaces in a string?

Example: I'm trying to replace all of the spaces with "%20" and "#" with
"%23", etc. I also need to replace the "?", "!", " ' ", etc.

I know I can do this with:
thisString.Repl ace(" ", "%20")
thisString.Repl ace("#", "%23")

But, I'm trying to find a way to do this one line of code.

Any Ideas?

TIA

JS

Nov 15 '05 #3

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

Similar topics

5
1266
by: David | last post by:
Hi, I have a replace function <%= Replace(arData(0,i), "_", " ")%> that works fine to replace the _ with a space, but I'd also like it to look for, and replace one word with another in the same string (E,G replace the word "Right" with "Wrong"). The code is located in a table that is displaying the results of a database search. I'm having problems with a) finding out if it's possible to do it this way, and b) what the syntax should...
2
1607
by: JeeWee | last post by:
Hi all, I'm looking for a way to "bind" multiple eventhandler function to the same event. In other languages this can often be done by using the += operator, unfortunately this doesn't seem to work. My (working) code for assigning an eventhandler for some form elements is: for( var i = 0; i < document.formx.elements.length; i++ ) { document.formx.elements.readonly = true;
32
14852
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
4
8872
by: tshad | last post by:
I have a textbox that I am storing as text (or as a varChar). The field has multiple lines in it (not wrapped). When I read it back into a multiline textbox, it works fine. But when I read it back into a label, it shows all lines together. Is there a way to get the Label to display the lines separately? I could use textbox and get rid of the border and set enable to false, but then it greys the text, which I don't want.
4
3123
by: Neo Geshel | last post by:
Greetings I am using VB in my ASP.NET project that uses an admin web site to populate a database that provides content for a front end web site. I am looking for a way to use replace() to replace multiple entries of an object within a string. That is, if a user hit twice to create one new line, but just once to create another, I want both types ( & twice to create a new line (by creating a blank line between paragraphs). ...
0
3077
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not want to replace all of them. You need to look at it in a case-by-case basis. What can you do? Answer: emacs.
1
1483
by: vbisjustforme | last post by:
sup guys, hit a mental snag an need some help. i want to search a defined string (textbox), and replace all characters in that string to Hex(KeyAscii) with "%" in front of the Hex(KeyAscii) right now my problem is i can do this in the textchange and keypress etc with one replace function eg . txtpass1 = Replace(txtpass, "&", "%26") works no probs ... however there are multiple instances i need to change if they are present in txtpass...
4
1946
by: gblack301 | last post by:
Hi, I have a search form where the user can check a box or enter some data such as a name to quey the database. I was wondering what is the best way to enable the ability for a user data in more than one field or check muliple boxes to query the database. What I want to do is create a multiple search criteria data string. Below is the code that working with a the moment. Any input would be appreciate. Thanks Greg If...
27
2121
by: cmdolcet69 | last post by:
Can anyone tell me if its possible to do multiple event args in vb.net?
0
8598
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9014
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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...
1
6515
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
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...
1
3037
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
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.