• Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal escape character  RSS feed

 
Habib Salhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone..

im trying to do a simple string compare to the "-" by using this command

if(somestring.equals("-"))

and i get an error saying "Incorrect syntax near ')'."

and when i try to escape it by using
if(somestring.equals("\-"))

i get "illegal escape character" at compile time

any clues..
many thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The time to have Java code in your JSPs is long past. Java scriptlets in JSP have been discredited since 2002. Your best bet is to refactor your code such that your JSP contains no Java. This article might be helpful.

Meantime, you'll need to show us a little bit more of the surrounding code for us to help you with this particuar problem. Please be sure to use code tags when posting code (see ⇒ UseCodeTags).
 
Habib Salhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the comment about refracting.. actually im not a Java/jsp programmer nor do i plan to be in the future.. this is a one time job that i had to do for an E-learning software called blackboard and i am developing a building block for it and this seems to be the way in other building blocks..

anyways.. with that said.. here is some of the surrounding code


 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you editing this code? Hopefully not with a word processor which might use "smart" punctuation for quotes and other punctuation characters.

Bill
 
Habib Salhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use netbeans so it wud show me any punctuation error.. i doubt that is the case..

can someone please try it in any java page you have.. both the direct compare and with the character escape and tell me if it works..

it must be misinterpreting the "-" character.. and what is the correct escape for it ??

regards
 
Paul Clapham
Sheriff
Posts: 22379
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible that the error message you're getting -- notice that you haven't posted it yet -- is occurring when you execute that SQL
statement -- which you are constructing by concatenating strings, another bad practice?

In that case it would be a message about escape characters in your SQL. Which wouldn't be surprising given the error-prone-ness of
constructing an SQL statement that way. It's easy to miss out a quote, or put one which doesn't belong, or think you put a quote into
your SQL but you actually put it into your Java code.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Habib Salhi wrote:I use netbeans so it wud show me any punctuation error

Please use real words when posting to the forums. Abbreviations such as "wud" in place of "would" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please click this link ⇒ UseRealWords for more information.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!