Solved

storing a string

Posted on 2003-12-01
16
263 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

828 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