🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19852

Re: '\n' at start of StringBuffer??

#19852
From: Anand Srinivasan
Date: Tue, 09 Dec 1997 00:00
53 lines
1980 bytes
On Windows, a carriage-return is '\r\n'. Since you are using \r as a
delimiter, every string (after the first one) will contain the \n at the
beginning. You can code so that you check for a \n if the platform is
windows. On unix your present code will work fine.

Btw there is a readline method that will do what you want.

Anand

Paul Richards wrote:
> 
> I'm trying to capture keyboard input and put it into a String so I have
> a number of methods of the form:
> 
>  void getName()
>     {
>       System.out.print( "Enter full name : " );
>       sb = new StringBuffer();
>       try
>       {
>         while ( ( c = (char)System.in.read() ) != '\r' )
>           sb.append( c );
>           name = String.valueOf( sb.toString() );
>       }
>       catch ( IOException e )
>       {
>         System.out.println( "IO error" );
>         e.printStackTrace();
>       }
>     } // end getName()
> 
> where 'name' is a String variable defined as part of my class.
> I have a number of other methods such as getAddress1(), getAddress2()
> and getAddress3().
> 
> When I look at the variables in the JBuilder debugger I'm getting the
> following:
> 
>  name     'aaaaa'
>  address1 '\nkkkkkkkkk'
>  address2 '\nmmmmmmmmm'
>  address3 '\nggggggggg'
> 
>  I'd have expected '\n' to appear at the *end* of the variable. Can
> anyone explain what is happening?
> 
> TIA
>  ++ *Paul*
>  ++ from Cheltenham, England
>  ++ Tue, 09 Dec 1997 19:29 GMT
>  ++ WinNT build 1381 + SP3
>  ++ http://freespace.virgin.net/paul.richards/
Technical Details
Message-ID: <348DA163.2C67412E@2-cool.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <VA.00000025.0f60688c@p5>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,8cab8c7f06de7a47
X-Google-Attributes: gidf74b3,public
From: Anand Srinivasan <anand@2-cool.com>
Subject: Re: '\n' at start of StringBuffer??
Date: 1997/12/09
Message-ID: <348DA163.2C67412E@2-cool.com>
X-Deja-AN: 296685063
References: <VA.00000025.0f60688c@p5>
Organization: None
Newsgroups: borland.public.jbuilder.java.language