• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

annoying JSP error

 
Devin Fleenor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a page that works well - until I try to do a simple

function. The actual code is:



where I am basically trying to remove any spaces in the string "STnospace".
But when I go to that page in the browser, it is giving me these errors:



Any ideas what I am doing wrong?

Thanks,
Devin
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64993
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do realize that in Java the double quote is used to denote String literals and that the single quote is used to denote character literals?
 
Bonagiri UmaMaheshwar Rao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use the following statement for your conversion.
s= s.replaceAll(" ","");
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi devin
I guess you will have to write a small piece of code which will split the string depending on the number of spaces and concatenate the seperate strings together.
You will have to use the String.substring() and String.indexOf() in a loop and generate a new string.
Try it out.
This is one way to do it.
If there is any other way do please let me know if you come across it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64993
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you will have to write a small piece of code


No, he can use the replaceAll() method as he plans. He just needs to get his syntax correct.
 
Devin Fleenor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the help, I was just coming back here to mention that I had discovered
the String.replaceAll() method and got it working.

Bear: yes, I knew that - what I didn't know is that '' isn't accepted as a character!

Niki: I think your method would be good excercise on using String.substring() and String.indexOf() - so i might try it that way even though the String.replaceAll() is much easier.
[ April 13, 2005: Message edited by: Devin Fleenor ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic