Solved

storing a string

Posted on 2003-12-01
16
261 Views
Last Modified: 2011-09-20
Im reading a string from a server, how can I store it in a variable before displaying it?, the code below just displays the string.

while( ( buffer = input.readLine() ) != null )
          display.appendText( "\n" + buffer ) ;
          }
0
Comment
Question by:eire_ireland
  • 7
  • 4
  • 3
  • +2
16 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9853797
Just save it to a variable. Of course it will be overwritten each time in the loop

String savedString = buffer;
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9853800
What is it you're trying to achieve?
0
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
ID: 9853806
How about:

String store="";
while( (buffer=input.readLine())!=null)
{   store+=buffer;
    display.appendText("\n"+buffer);
}

This will put the whole input into the String named stored.
0
 
LVL 92

Expert Comment

by:objects
ID: 9853916
String buffer = null ;
   StringBuffer todisplay = new StringBuffer();
        while( ( buffer = input.readLine() ) != null )
          todisplay.append( "\n" + buffer ) ;
          }
    display.setText(todisplay.toString());
0
 
LVL 92

Expert Comment

by:objects
ID: 9853942
use following if you want to append the read text:

display.appendText(todisplay.toString());
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9854036
It's already stored in a variable in your question.  It's stored in "buffer".
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9854106
If 'display' is a text component like a TextArea then it's stored anyway and you can get it back as follows:

String original = display.getText();
0
 
LVL 92

Expert Comment

by:objects
ID: 9854123
> It's stored in "buffer".

Not the entire string read.

> String original = display.getText();

That returns the string displayed in the text field, and not the string read in.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:CEHJ
ID: 9858314
>>That returns the string displayed in the text field, and not the string read in.

The value, if taken just after the text field is set, is exactly the same as the value contained in the StringBuffer 'todisplay' that you suggested, which is redundant if 'display' is a text component of some kind, as the String is already buffered.
0
 

Author Comment

by:eire_ireland
ID: 9860487
Cheers bucks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9860594
What does type does 'display' refer to eire_ireland?
0
 

Author Comment

by:eire_ireland
ID: 9860673
A string, I dont think i know what u mean
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9860768
>>display.appendText()

'display' can't be of type String, as it does not have an appendText method
0
 

Author Comment

by:eire_ireland
ID: 9860801
well im using display.appendText, whats has this to do with anything anyway
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9860879
Never mind - i don't want to labour the point!
0
 

Author Comment

by:eire_ireland
ID: 9860926
Fair enough, I was worried there for a second that you were lookin for advice off me!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now