Is there anything similar to StringBuffer in Smalltalk ?

瀏覽次數:109 次
跳到第一則未讀訊息

Narender Sharma

未讀,
2011年9月7日 上午10:37:082011/9/7
收件者:va-sma...@googlegroups.com

Louis LaBrunda

未讀,
2011年9月7日 下午4:54:012011/9/7
收件者: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

未讀,
2011年9月7日 下午5:53:482011/9/7
收件者:va-sma...@googlegroups.com
StringBuffer have one feature: they are changeable. Instances of String are not changeable.


Louis LaBrunda

未讀,
2011年9月7日 下午6:26:532011/9/7
收件者:va-sma...@googlegroups.com
Changeable like this:

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


Marten Feldtmann

未讀,
2011年9月8日 凌晨1:10:272011/9/8
收件者: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

未讀,
2011年9月8日 上午8:46:382011/9/8
收件者:va-sma...@googlegroups.com
You must know that already, but string litterals are read-only for very obvious reasons.


訊息已遭刪除

Narender Sharma

未讀,
2011年9月8日 上午10:15:002011/9/8
收件者:va-sma...@googlegroups.com
Thanks Louis, WriteStream was something that I needed.

Louis LaBrunda

未讀,
2011年9月8日 下午4:07:212011/9/8
收件者: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

未讀,
2011年9月15日 清晨6:24:292011/9/15
收件者: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!
回覆所有人
回覆作者
轉寄
0 則新訊息