Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to insert escape sequence in a string?  RSS feed

 
Naresh Rajan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is quite unique. I get values through a text box and the value can have single quote or a double quote. am using struts. I will be displaying the info after the action class. So the back slash should not be displayed. I tried to replace using replaceall. But didnot work. Pls help me.!!!
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, actually we should move this thread to the Java In General (Beginner) forum. It is really about Strings, even though you have Servlets and Struts.

By the way, we also have a Struts forum too.

Good Luck

Mark
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

Can you show us what you tried with replaceall and explain what it didn't do for you? Cheers!
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user shouldn't need to type a back slash to escape double- or single-quotes. The computer will store the quotes as they should be and print them normally. The main reason for escape characters is because some characters have special meaning in a specific context. For example, in your Java code, you need to escape ' and " because Java treats them specially. However, I suspect that this is not necessary in the text the user enters in the text area.

Please let me know if I am off the mark. It will help if you explain what kind of text the user is expected to enter (i.e. what does it mean?).

Layne
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isn't there a escape(...) or somthing? Pardon me if I'm misunderstanding you are am blatenly wrong.
 
Naresh Rajan
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will explain the problem clearly.

problem 1:

I have a text box that gets address info. If say a Building name is in double quotes say '"White House"'. Then when i try to sign the data for digitally signing it and i pass it as a concatenated string to the funtion that calls the signing component, it throws an error and the data is not signed finally.

The total string is "Raghu123,"WhiteHouse"NewYorkUSA".
--------------------------------------------------------------------------

Problem 2:

The next case is, I am calling a function in a jsp and it passes the string to the funtion as an input parameter.

The function call is:

onsubmit='javascript:showapp"1001000111,D'Souza,walter"'

the function is:

showapp(int,string1,string2){
..........
..........
}

In this case the call is not complete as the whole data doesnot reach the function.

In both the cases if I insert an escape sequence the problem will be solved. So pls help me.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!