Solved

storing a string

Posted on 2003-12-01
16
260 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 32
What is the latest versions eclipse neon 2 122
Java asynchronous logging 4 35
eclipse formatting 6 43
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

747 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

12 Experts available now in Live!

Get 1:1 Help Now