Is there anything similar to StringBuffer in Smalltalk ?

109 views
Skip to first unread message

Narender Sharma

unread,
Sep 7, 2011, 10:37:08 AM9/7/11
to va-sma...@googlegroups.com

Louis LaBrunda

unread,
Sep 7, 2011, 4:54:01 PM9/7/11
to 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

unread,
Sep 7, 2011, 5:53:48 PM9/7/11
to va-sma...@googlegroups.com
StringBuffer have one feature: they are changeable. Instances of String are not changeable.


Louis LaBrunda

unread,
Sep 7, 2011, 6:26:53 PM9/7/11
to va-sma...@googlegroups.com
Changeable like this:

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


Marten Feldtmann

unread,
Sep 8, 2011, 1:10:27 AM9/8/11
to 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

unread,
Sep 8, 2011, 8:46:38 AM9/8/11
to va-sma...@googlegroups.com
You must know that already, but string litterals are read-only for very obvious reasons.


Message has been deleted

Narender Sharma

unread,
Sep 8, 2011, 10:15:00 AM9/8/11
to va-sma...@googlegroups.com
Thanks Louis, WriteStream was something that I needed.

Louis LaBrunda

unread,
Sep 8, 2011, 4:07:21 PM9/8/11
to 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

unread,
Sep 15, 2011, 6:24:29 AM9/15/11
to 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!
Reply all
Reply to author
Forward
0 new messages