Solved

storing a string

Posted on 2003-12-01
16
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
String array comparison 4 55
What browser will run Java? 7 168
How to log java errors in tomcat 8 35
Tomcat 9 + java 8 error while trying to deploy a war file 2 841
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

738 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