Solved

How do I get CF Server to ignore the double quotes within strings and variables.

Posted on 2002-07-17
12
189 Views
Last Modified: 2013-12-24
my problem is simple I have a comapany name that contains ""in it how do I get the server to ignore those.

right now it is cutting the name out at the first instance of ".

example

cfset company = "my job "athome"">

at the output it only displays

MY job.....



its probly real simple
0
Comment
Question by:jriver12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 3

Expert Comment

by:SewellM
ID: 7160208
You can escape the "'s.
<cfset company = "my job ""athome""">

Michael
0
 
LVL 5

Expert Comment

by:CFXPERT
ID: 7160230
or use single quotes like this

<cfset company='my job "athome"'>

This would work also
0
 

Author Comment

by:jriver12
ID: 7160244
so if I was passing the company variable thru the url from a form, would I pass it like
?company='#form.company"'&anothervariable=#another#??



0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 17

Accepted Solution

by:
anandkp earned 50 total points
ID: 7161283
Hi there,

The bost possible solution would be - replacing all ur doubel quotes ["] with 2 single quotes ['']

since they appear same in display - it works fine.

try it & let me know.

K'Rgds
Anand
0
 

Author Comment

by:jriver12
ID: 7163224
I think I need to rephrase.

I am not setting a variable that contains something"something"Somethingelse

the user elects to use "" within letsay the company name.

how do I get cf to  escape the doublequotes so the entire content of the variableshows
0
 
LVL 5

Expert Comment

by:CFXPERT
ID: 7163282
If its in the database as lets say:

"myCompany"

then CF should output it just the same.
<cfquery name="myQuery" dataasource="whatever">
sleect companyName
from companies
</cfquery>

<cfoutput query="myQuery">
#companyName#<br>
</cfoutput>

This should be no problem.  The only time you should have problems with single or double quotes is when you do an insert or update.

Are you displaying a the company name just from a posted form or from an SQL query?

Can you post all of your code?
0
 
LVL 17

Expert Comment

by:anandkp
ID: 7164006
Hi again,
I understand that u r not setting a variable.

but when u try & display this data containing double quotes [as inserted in DB] - it gives u a problem right.

so wehn u display this data use -

#Replace(data,'"',"''",'All')#

u can use this to display ur data - without ne-erros & it will be printed as if its double quotes - though its acutally 2 single quotes.

===========================================================

u could also have another way to work around this ...

ie in ur application.cfm file - set a variblae called
<cfset doublequote = '"'>

Now every time u insert data in ur data base use

replace(data,'"','##doubleQuotes##','all')

what this would do - is insert data in ur table as - lets say
anand#doublequotes#s [instead of anand"s]

but when u display this variable as it is on ne-page.

this value would be displayed as anand"s - as #doublequotes# is initialised in UR application file.

Hope this helps out
else let me know

K'Rgds
Anand
0
 

Author Comment

by:jriver12
ID: 7169237
This is getting even weirder.

when I output my data containing "" in the variable like
Mr.Ts "house"

when I output it like this
<cfoutput>#mrtsvariable#</cfoutput>
it displays Mr.Ts "house" thats great.

now when I display the same variable in this manner
<cfoutput><input type="text" name="textline" value='#mrtsvariable#'>

it displays like this in the field:
Mr.ts
hence cutting off the "house" part.

any suggestions.....
0
 
LVL 17

Expert Comment

by:anandkp
ID: 7169269
Hi there,

I told u replace ur Double quote with 2 single quotes & then display ur value in textbox as
ie ur variable becomes - Mr.Ts ''house''

<input type="text" name="textline" value="#mrtsvariable#">

there u go - it gets displayed competely without getting cut.

==========================================================

abt ur q's it b'cos - when displaying there r no quotes surrounding the variable - but when u display it in a text box - u have it enclosed in the quotes of the value attribute of the input box.

hope that makes things clear ....

K'Rgds
Anand

0
 
LVL 2

Expert Comment

by:hammond_david
ID: 7174458
Hi, there.

How you deal with a variable that may contain quotes depends on where you're using it, and Cold Fusion has functions specifically designed to do what you need.  If you are putting the variable in the query string of a url, use the URLEncodedFormat function:

?company=#URLEncodedFormat(form.company)#&anothervariable=#URLEncodedFormat(another)#

If you want to display the value in an input form field, use the HTMLEditFormat function, which will also guard against someone using html code:

<input type="text" name="textline" value="#HTMLEditFormat(mrtsvariable)#">

0
 
LVL 17

Expert Comment

by:anandkp
ID: 7176297
Hi David,

I have tried using HTMLEditFormat - but this dosent help in escaping the single & double quotes present within the string.

thats why i came up with the replace function ...

ne-ways,

K'Rgds
Anand
0
 

Author Comment

by:jriver12
ID: 7179893
thanks yall. :^)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Server with multiple sites and SSL 14 74
htaccess restrict subdomain 4 146
WEB Farm 6 83
Web site: http forwards to https causing 301 errors - SEO issue? 26 73
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
What You Need to Know when Searching for a Webhost Provider
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question