Some issues about strings and integers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Some issues about strings and integers

Ian Jiang
Hi,

I came across such an situation:

I have a window which contain an inputTextField and two buttons. One button is to save the current value of the text field into a file while the other is to load the value which stored in the file to the input text field. Besides, the format of the inputTextField is Number. As I learned from the tutorial, when to save, I can get only an Integer from the inputTextField; when to load, I have to return an integer to the valueholder. I have to deal with the problem between integer and readstream or writestream. Is there any better way to do this work?

I am looking forward to your kind help and thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Some issues about strings and integers

Ian Jiang
I am still looking forward to your kind help.

Ian Jiang wrote
Hi,

I came across such an situation:

I have a window which contain an inputTextField and two buttons. One button is to save the current value of the text field into a file while the other is to load the value which stored in the file to the input text field. Besides, the format of the inputTextField is Number. As I learned from the tutorial, when to save, I can get only an Integer from the inputTextField; when to load, I have to return an integer to the valueholder. I have to deal with the problem between integer and readstream or writestream. Is there any better way to do this work?

I am looking forward to your kind help and thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Some issues about strings and integers

Reinout Heeck-2
Ian Jiang wrote:
> I am still looking forward to your kind help

I was originally a little confused by your problem description, but on a
second read I understand that you want to know how to obtain an Integer
from a ReadStream.

If the stream contains text you can try to use Integer class>>readFrom:
but be aware that you have to position your stream at the beginning of
the integer (otherwise it returns 0 without advancing the stream; this
can easily create an endless loop). Writing can be done using the
#printOn: method of your number, this is called indirectly by using
#print: on the writeStream.

Text examples:
|rs|
rs := '1 2 3' readStream.
[rs atEnd] whileFalse: [
    (Integer readFrom: rs) inspect.
    rs skipSeparators].

|ws|
ws := String new writeStream.
1 to: 3 do: [ :n |
    ws print: n; space].
ws contents inspect


Reading from binary file can also be done, but support is only available
for external streams (on files and sockets) and only for one endianness.
See for example implementers of #nextWord #nextWordPut: nextLong:
nextLongput: etc.




Sorry for the late response, we usually are a nicer bunch of people here ;-)

Reinout
-------

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc