This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Escape characters

 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a piece of code in my JSP:

<%
String text = "#" ;
request.setAttribute("text", text);
%>
<%=text%>

Currently it displays as #. I need it to change to %23.

Also can I ask somebody to please differentiate escaping vs. encoding? Thank you very much
 
Charbel Keyrouz
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encoding in your case is url encoding means replacing the spaces for example with %20.
The purpose of the encoding is the replacing of some character with their hex code so to make sure that the characters will be transmitted correctly as they are.

The escaping character allows the compiler to jump over the next character without checking it.
example:

if you want to go to another line in java you concatenate your string with \n.
So the \ character is a key to an action and once you have written \n the compiler will go to another line while executing.

so the \ is an escaping characher.
if you need to print the " symbol inside a string you say: String t = "i want to print the \" character as is.";
with the usage of the \ character the compiler will not consider the " as end of string but as a normal character that will be printed like any other one.

Hope I was clear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic