Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

How do I substitute all spaces with plus symbol in a text input field

Hello all,

I am looking for a way to substitute all space characters in a given text input field with the plus symbol.  For instance, the original field value of the text input might be something like "123 Main St." and I would like to substitute it as "123+Main+St.".

Thanks in advance for helping with this!
0
dstjohnjr
Asked:
dstjohnjr
  • 5
  • 2
1 Solution
 
INSDivision6Commented:
<cfset addr="123 Main St">

<cfset addr2=Replace(addr, " ", "+", "ALL")>
<cfoutput>#addr2#</cfoutput>
0
 
Tacobell777Commented:
I think you are looking for urlEncodedFormat("123 Main St.")
0
 
Tacobell777Commented:
You want to pass the string via the url right? Or am I assuming to much?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
dstjohnjrAuthor Commented:
No, this is not in the URL, it is on a form with multiple fields.  The fields that would typically have spaces to be substituted with the plus symbol are:

SiteName
StreetAddress
City
State
Zip
Phone

although the fields that most typically have the spaces to be substituted are SiteName, StreetAddress and Phone.

I am going to try the code initially recommended by INSDivision6 and will be back here with my results either way.

Thanks!
0
 
Tacobell777Commented:
Can I ask why you are doing this?
0
 
dstjohnjrAuthor Commented:
Certainly.  I have a client that has hundreds of restaurants in the US and Canada.  They have a backend database application that stores all of the information about the restaurants.  In addition to the standard location fields (address, city, state, zip, etc.) there are also fields that we use for Mapquest (i.e. MQAddress, MQCity, MQState, etc.).  The Mapquest fields cannot contain any spaces - only the plus symbol (presumably because we are passing this information in the URL line - which would probably substantiate your initial question).  So, for our client, we have a data entry process whereas whenever they open a new restaurant, they first have to enter basic location information about the restaurant.  The next step is to to configure the location to be used with Mapquest.  When they enter the form to configure the location to be displayed with Mapquest, we are pre-populating the form with values from the initial address information they entered, then substituting all spaces with the plus symbol so that they really don't have to do anything further except to submit the form.  Does that make sense?

Thanks!
0
 
Tacobell777Commented:
yup makes sense, if you are about to pass any data over the url you need to think about more characters than just the space, which is why cf provides urlEncodedFormat()

I would strongly suggest you use that instead, it does not convert a space to a plus, but %20 which is the html equivalent of a space.
0
 
Tacobell777Commented:
ok dont listen.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now