Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!howland.reston.ans.net!nntp.crl.com!pacbell.com!amdahl.com!amd!amd.com!txnews.amd.com!news
From: "Paul G. Schaaf, Jr." <paul.schaaf@amd.com>
Subject: Re: newbie question on concatenating strings
Content-Type: text/plain; charset=us-ascii
Message-ID: <DE1pE0.61o@txnews.amd.com>
Sender: news@txnews.amd.com
Nntp-Posting-Host: hqsp86
Content-Transfer-Encoding: 7bit
Organization: Advanced Micro Devices
References: <1995Aug28.130019.29932@vtf.idx.com>
Mime-Version: 1.0
Date: Tue, 29 Aug 1995 00:01:09 GMT
X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
Lines: 42

sra@idx.com (Steve Alpert) wrote:
>I just finished a short course in OOP using another language and I dragged
>my old Smalltalk/V 1.1 out and thought I'd try the "real thing."  I'm
>trying to return as the value of a method a string that is the
>concatenation of both instance variables (strings) and constant strings.
>
>Do I have to create the "+" method for strings?  Anyone got a simple
>solution?
>
>tnx, steve
>

Smalltalk-80 defines the concatenation operator as #, (the comma).
It is a binary operator, used as follows:

   | stringA stringB stringC |
   stringA := 'Smalltalk'.
   stringB := 'is fun.'.
   stringC := stringA , ' ' , stringB , Character cr asString.

If you're going to concatenate several strings together it is more 
efficient to use a stream:

   | stringA stringB stream stringC |
   stringA := 'Smalltalk streams'.
   stringB := 'are even more so.'.
   stream := WriteStream on: (String new: 10000).
   stream
      nextPutAll: stringA;
      nextPut:    Character space;
      nextPutAll: stringB;
      cr.
   stringC := stream contents.

----------------------------------------------------------------------
Paul.Schaaf@AMD.Com              Advanced Micro Devices, Sunnyvale, CA
I don't speak for my company                        http://www.amd.com

"In theory, there is no difference between theory and practice, but in
 practice, there is." - unknown


