• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

annoying JSP error

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use the following statement for your conversion.
s= s.replaceAll(" ","");
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic