Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invalid character constant

 
Matthew Turner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys i am trying to use string.replace in my jsp to convert a path name eg. s:\hi\hi\hi.jpg to s:/hi/hi/hi.jpg.

this is my code,

finishedURL = fileName.replace( '\' , '/');


but sadly tomcat says,

org.apache.jasper.JasperException: Unable to compile class for JSPS:\tomcat\work\localhost_8080\_0002fmapCreate_0002ejspmapCreate_jsp_37.java:160: Invalid character constant.
finishedURL = fileName.replace( '\' , '/');
^
S:\tomcat\work\localhost_8080\_0002fmapCreate_0002ejspmapCreate_jsp_37.java:160: Invalid character constant.
finishedURL = fileName.replace( '\' , '/');
^
S:\tomcat\work\localhost_8080\_0002fmapCreate_0002ejspmapCreate_jsp_37.java:160: ')' expected.
finishedURL = fileName.replace( '\' , '/');
^

i am using the java api but obviously this is not the way to do it, any help you could give would be great.
Thanks,
Matt T
 
Preetham Chandrasekhar
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put the value in <variable_name>.replace() in double quotes as <variable_name>.replace("\","/"); i am guessing that should work
 
Matthew Turner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah already tried that, but the parameters are characters not strings, actually i think it has something to do with the / character but i am not sure what?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The backslash is the Java string escape character - '\' is a single quote opening a character constant, followed by the (escaped) character which is a single quote, with no following terminator thereby invalid. I think you meant '\\'.

- Peter
 
Matthew Turner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah works a treat, thanks for that.

cheers,
matt
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic