[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: How to detect a "blank" line.



Hi,

In your java program, exchange the line
	if (s1.charAt(0)!='#') { // not a comment or NULL line
with
	if (s1.equals("") || s1.charAt(0)!='#') { // not a comment or NULL line

Explanation:
You get empty lines as empty strings from readLine(). So you first have
to check whether the string s1 is empty. This is done with
s1.equals(""). If this yields true, the evaluation of the conditionalin
the if-statement is terminated, you get true. I the string is not empty,
the evaluation is continued. Now, that you know that the string is NOT
empty, you can check for the first character. If you try to check the
first character without knowing for shure that the string is not empty,
this will throw errors, since empty strings have no characters.

I didn't investigate your C programm. I suppose it has a simular
mistake. If you can't figure out yourself, please mail again.


Matthias Pfisterer



Chien-Lung Wu wrote:
> 
> Hi,
> 
> The code in JAVA is as following:
> [...]
 
> C.L.
> 
> On Wed, 7 Jul 1999, Matthias Pfisterer wrote:
> 
> > Please show us the code you used. That would make it much easier to
> > understand your problem and to help you.
> >
> > Matthias Pfisterer
> >
> >
> > Chien-Lung Wu wrote:
> > >
> > > Hi,
> > > I try to read in a text file like follow,
> > >
> > > # comments
> > > #
> > > line1 with information
> > > line2 (blank)
> > > line3 with information
> > > line4 (blank)
> > > # comments
> > > #comments
> > >
> > > I write my program in C  and also try to use JAVA. One thing very
> > > interesting is my program can read-in this text file line by line (ether
> > > in C or in JAVA) if no any blank line. If I edit the text file with some
> > > blank line, I ether can not trin this line out (in C) or I get a error
> > > message " line out of range". How can I detect a blank line and trim it
> > > out?
> > >
> > > Any suggestion will be appreciated. Thanks,
> > >
> > > C.L.
> > >
> > > ----------------------------------------------------------------------
> > > To UNSUBSCRIBE, email to java-linux-request@xxxxxxxxxxxxxxxxxx
> > > with a subject of "unsubscribe". Trouble? Contact listadm@xxxxxxxxxxxxxxxxxx
> >
> 
> ****************************************************************************
> Chien-Lung Wu                                           cwu4@xxxxxxxxxxxx
> Graduate Student of ECE                                 (O) 919-513-1894
> at North Carolina State University                      (H) 919-233-6724
> ****************************************************************************

- --------------------------------------------------------------------
For more information on Linux in India visit http://www.linux-india.org/
Please do not post HTML email to this mailing list.  HTML mails will be
thoroughly ignored and derisively sniggered at in private.

------------------------------