• 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

String search/replace.

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, it's all cosmetic from here. The prog works & functions very well.
But... don't ya love it...
I want to strip the double quotes from the fields when I read it in & then put them around it when I write it back out. I also need to strip/replace 2 bang signs (!!) at the front of 3 of the fields. I read the strings into the string lineOfInput. I then use string test = lineOfInput.replace('"',' '), it compiles, but I get a runtime error...

C:\Dev\JavaProjects\Editmsg>java FileEdit
Exception in thread "main" java.lang.NullPointerException
at FileEdit.main(FileEdit.java:333)
333 is the line of the replace.
I just read the previous post on string replace & my syntax looks correct.

Thanks again, -Bill.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
readLine() returns null at end of file; you're probably already using this fact to break out of a loop. Just be sure the line isn't null before you do the replace.
 
Bill Raterink
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Earnest, thanks yet again. R U psychic, or WHAT? Without even seeing my code you knew I was using the != null test in my while loop. I think I'll need an additional book, the 2 I have are just not cutting it. Que's "JAVA Quick Reference", Michael Afergan, & the "Beginning Programming with Java for Dummies", Barry Burd, NEITHER tell me that the readline() returns a null at eof. Still, that's no excuse, I should have realized it by the test in the sample code. I'm going out this weekend & try something else. Thanks again. -Bill.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I'm not psychic, just omniscient.
 
Bill Raterink
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh Omnicient One... why does my output now have a 100 in front of it? I've taken your suggestion & the quotes & !! strip off easily. But when I try to put them back on, well... it's just what greenhorns do.
I suspect the char can't be "tacked onto" a string, but String or Byte didn't improve things any either. Here's a piece of my mess...

Is there a better way to do the ??? line? concat?, etc. I read the post on strings, but it was a bit over my head just yet. Thanks, -Bill.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way to fix it would be to change this:

to this:

Brian
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly. The + operator only concats string; it adds everything else. Remember that a char is really a number behind the scenes. A Quote is ASCII 34 and a Bang is ASCII 33. When you say quote + bang + bang, you are really saying 33 + 33 + 34, which is 100. Then it adds the string (It converts the 100 to a string and then concats).
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
No, I'm not psychic, just omniscient.


I'm thinking more along the lines of omnipresent Ernest!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic