• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

storing a string

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
eire_ireland
Asked:
eire_ireland
  • 7
  • 4
  • 3
  • +2
1 Solution
 
CEHJCommented:
Just save it to a variable. Of course it will be overwritten each time in the loop

String savedString = buffer;
0
 
CEHJCommented:
What is it you're trying to achieve?
0
 
imladrisCommented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
objectsCommented:
String buffer = null ;
   StringBuffer todisplay = new StringBuffer();
        while( ( buffer = input.readLine() ) != null )
          todisplay.append( "\n" + buffer ) ;
          }
    display.setText(todisplay.toString());
0
 
objectsCommented:
use following if you want to append the read text:

display.appendText(todisplay.toString());
0
 
jimmackCommented:
It's already stored in a variable in your question.  It's stored in "buffer".
0
 
CEHJCommented:
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
 
objectsCommented:
> 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
 
CEHJCommented:
>>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
 
eire_irelandAuthor Commented:
Cheers bucks
0
 
CEHJCommented:
What does type does 'display' refer to eire_ireland?
0
 
eire_irelandAuthor Commented:
A string, I dont think i know what u mean
0
 
CEHJCommented:
>>display.appendText()

'display' can't be of type String, as it does not have an appendText method
0
 
eire_irelandAuthor Commented:
well im using display.appendText, whats has this to do with anything anyway
0
 
CEHJCommented:
Never mind - i don't want to labour the point!
0
 
eire_irelandAuthor Commented:
Fair enough, I was worried there for a second that you were lookin for advice off me!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 7
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now