Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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