Is there anything similar to StringBuffer in Smalltalk ?

109 visualizzazioni
Passa al primo messaggio da leggere

Narender Sharma

da leggere,
7 set 2011, 10:37:0807/09/11
a va-sma...@googlegroups.com

Louis LaBrunda

da leggere,
7 set 2011, 16:54:0107/09/11
a va-sma...@googlegroups.com
Hi Narender,

I don't know a lot about Java and StringBuffer, so I may be misunderstanding your question but I think normal Strings should do it.

aString := 'first part', someStringVariable, 'last part'.

The "," comma will concatenate the strings.  Also take a look at the WriteStream class.  It is useful for building large strings with less overhead than string concatenation.

stream := WriteStream on: (String new: 1000).
stream nextPutAll: 'first part; nextPutAll: someStringVariable; nextPutAll: 'last part'; cr; cr; tab; nextPutAll: 'some more stuff'.
aString := stream contents.

Lou

Marten Feldtmann

da leggere,
7 set 2011, 17:53:4807/09/11
a va-sma...@googlegroups.com
StringBuffer have one feature: they are changeable. Instances of String are not changeable.


Louis LaBrunda

da leggere,
7 set 2011, 18:26:5307/09/11
a va-sma...@googlegroups.com
Changeable like this:

| s |
s := 'a string' copy.
s at: 1 put: $*.
s inspect.
s


Marten Feldtmann

da leggere,
8 set 2011, 01:10:2708/09/11
a va-sma...@googlegroups.com
Yes, I was not aware of that ... :-), but code like

| s |
s := 'a string'.

s at: 1 put: $*.
s inspect.
s

does not work, because it is a read-only object.

Normand Mongeau

da leggere,
8 set 2011, 08:46:3808/09/11
a va-sma...@googlegroups.com
You must know that already, but string litterals are read-only for very obvious reasons.


Il messaggio è stato eliminato

Narender Sharma

da leggere,
8 set 2011, 10:15:0008/09/11
a va-sma...@googlegroups.com
Thanks Louis, WriteStream was something that I needed.

Louis LaBrunda

da leggere,
8 set 2011, 16:07:2108/09/11
a va-sma...@googlegroups.com
Hi,

You are very welcome!  Now that you are feeling a little grateful, maybe you will forgive a personal and probably ignorant question on my part.  Which is your first or given name and which is your surname, Narender or Sharma?  I don't mean any disrespect.  I like to keep things friendly and informal on the forum and like to address people by their given name but sometimes it is hard to tell which is which.  Please forgive my ignorance of your culture.

Lou

Narender Sharma

da leggere,
15 set 2011, 06:24:2915/09/11
a va-sma...@googlegroups.com
Hi Louis,
             I am fine with Narender as well as Sharma. However Narender would be more apt :). Its good to keep things friendly and hence there is nothing to forgive.

Thanks!
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi