Greetings. I found a useful method. Only thing is I don't know how to write the character code for no character.
'12%31%%1232' replaceAll: $% with: $. '12.31..1232'
'12%31%%1232' replaceAll: $% with: $* '12*31**1232'
'12%31%%1232' replaceAll: $% with: '' ==> error '12%31%%1232' replaceAll: $% with: Nil ==> error
I looked for a deleteAll: method but there is none for Strings.
Thank you for your help.
Joe.
On Thu, 25 Oct 2012, Joseph J Alotta wrote:
Greetings. I found a useful method. Only thing is I don't know how to write the character code for no character.
'12%31%%1232' replaceAll: $% with: $. '12.31..1232'
'12%31%%1232' replaceAll: $% with: $* '12*31**1232'
'12%31%%1232' replaceAll: $% with: '' ==> error '12%31%%1232' replaceAll: $% with: Nil ==> error
I looked for a deleteAll: method but there is none for Strings.
Since the size of Strings (and Objects in general) can't be changed in Squeak, and removing characters would change the size, therefore you have to use a method which creates a new object instead of just modifying the receiver. Here are a few possibilities:
'12%31%%1232' copyWithout: $%. '12%31%%1232' copyReplaceAll: '%' with: ''. '12%31%%1232' reject: [ :each | each = $% ]. '12%31%%1232' select: [ :each | each ~= $% ].
Levente
P.S.: While #replaceAll:with: looks useful, it's a bit dangerous, because it changes the receiver. So you'll have to be more careful when you use it.
Thank you for your help.
Joe.
On Fri, Oct 26, 2012 at 05:26:58AM +0200, Levente Uzonyi wrote:
On Thu, 25 Oct 2012, Joseph J Alotta wrote:
Greetings. I found a useful method. Only thing is I don't know how to write the character code for no character.
'12%31%%1232' replaceAll: $% with: $. '12.31..1232'
'12%31%%1232' replaceAll: $% with: $* '12*31**1232'
'12%31%%1232' replaceAll: $% with: '' ==> error '12%31%%1232' replaceAll: $% with: Nil ==> error
I looked for a deleteAll: method but there is none for Strings.
Since the size of Strings (and Objects in general) can't be changed in Squeak, and removing characters would change the size, therefore you have to use a method which creates a new object instead of just modifying the receiver. Here are a few possibilities:
'12%31%%1232' copyWithout: $%. '12%31%%1232' copyReplaceAll: '%' with: ''. '12%31%%1232' reject: [ :each | each = $% ]. '12%31%%1232' select: [ :each | each ~= $% ].
Levente
P.S.: While #replaceAll:with: looks useful, it's a bit dangerous, because it changes the receiver. So you'll have to be more careful when you use it.
Also, the method finder will help you with questions like this. Open a method finder:
world menu -> open... -> method finder
Then enter an example of what you want, in the form of fields separated by periods, like this:
'12%31%%1232' . $% . '12311232' Accept this in the entry pane, and the method finder will suggest the #copyWithout: method and show you the classes in which it is implemented.
Dave
Joseph J Alotta pisze:
Greetings. I found a useful method. Only thing is I don't know how to write the character code for no character.
Hi Joe, For your information, there is a list for such newbie questions: beginners@lists.squeakfoundation.org, just to make things more organized. Kind regards, Mateusz
squeak-dev@lists.squeakfoundation.org