Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

Escape backslash followed by apostrophe

Thread view: 
Sisilla - 08 Nov 2007 19:21 GMT
Hello All,

I have a String object called "cargotype" that is assigned a value of
"20' Standard Container". I want to pass the cargotype object to a
javascript function, so I need to add a backslash before the
apostrophe to escape it. Ideally, I would like to pass "20\' Standard
Container" to the javascript function. I thought the following would
work-:

            cargotype = cargotype.replaceAll("'", "\\'");

What am I doing wrong here? I appreciate any effort to help me. Thank
you for your time and consideration.

Sincerely,

Sisilla
Daniel Pitts - 08 Nov 2007 19:29 GMT
> Hello All,
>
[quoted text clipped - 13 lines]
>
> Sisilla

replaceAll takes an Regex, and does a regex replacement.  Try "\\\\'".
I don't know that it'll work, so you'll have to try that yourself.

Basically, what that does is passes in the string \\' to the regex
handler, which escapes the \, and passes the \' to the javascript.

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Sisilla - 08 Nov 2007 19:38 GMT
Thank you, Daniel. It worked like a charm, and I really appreciate it.

Thanks,

Sisilla
Christian - 08 Nov 2007 19:53 GMT
Daniel Pitts schrieb:
>> Hello All,
>>
[quoted text clipped - 19 lines]
> Basically, what that does is passes in the string \\' to the regex
> handler, which escapes the \, and passes the \' to the javascript.

the first argument is a regexp not the second..
cargotype = cargotype.replaceAll(Pattern.quote("'"), "\\'");
should do the trick..
Daniel Pitts - 08 Nov 2007 19:59 GMT
> Daniel Pitts schrieb:
>>> Hello All,
[quoted text clipped - 24 lines]
> cargotype = cargotype.replaceAll(Pattern.quote("'"), "\\'");
> should do the trick..
The second one is the regex replacement, which isn't a normal string
either.  \1 represents the first captured group, etc...

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.