This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-12-27 22:56:07

djdolphin
Scratcher
Registered: 2010-03-23
Posts: 100+

Help With Squeak Smalltalk

In squeak, how do you convert a string, an argument, a string, and an argument into a string?

Help is greatly appreciated!  big_smile

Last edited by djdolphin (2011-12-28 08:07:51)

Offline

 

#2 2011-12-27 23:18:23

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: Help With Squeak Smalltalk

If your argument is a number, then you can just make the variable that you are using into a string.
Example:(t1 is a number)

Code:

t2 _ t1 asstring.

At least I think that's what it is.......

Last edited by GP1 (2011-12-27 23:19:56)


I am currently http://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=imagehttp://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=text and I finally got over 1000 posts.

Offline

 

#3 2011-12-28 08:31:17

djdolphin
Scratcher
Registered: 2010-03-23
Posts: 100+

Re: Help With Squeak Smalltalk

Thanks!

Offline

 

#4 2011-12-28 12:14:04

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Help With Squeak Smalltalk

It's actually:

Code:

t2 _ t1 asString.

I believe you need the capital letter.  (not asstring, asString)

To convert a string to a number:

Code:

t2 _ t1 asNumber

That will generate an error if the string has letters.  To make it report 0 instead of error, use:

Code:

t2 _ t1 asNumberNoError.

Last edited by Greenatic (2011-12-28 12:14:25)

Offline

 

#5 2011-12-28 12:19:41

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Help With Squeak Smalltalk

asNumberNoError is implemented in Boolean as well, so you can convert Booleans to numbers.

asString (by default) returns printString, a method which gives a representation of the object as a string. In other cases, you might want to use storeString, which gives a string that can later be used to reconstruct the object (it's valid Squeak code).

If you have a very large object, or want a shorter string, you can use printStringLimitedTo:, which acts like printString but cuts off the string at the given length.

Last edited by nXIII (2011-12-28 12:19:58)


nXIII

Offline

 

Board footer