String replace: Difference between revisions

From Cuis CookBook
Jump to navigation Jump to search
(importe material)
 
(syntax hilight)
 
Line 1: Line 1:
'''Problem'''. I have several file names ending with <code>.zip.b64</code>, I want to get rid of the <code>.b64</code> part of the string.
'''Problem'''. I have several file names ending with <code>.zip.b64</code>, I want to get rid of the <code>.b64</code> part of the string.


'''Solution'''. Use the <code>String >> copyReplaceAll: with:</code> message.
'''Solution'''. Use the <code>String >> copyReplaceAll: with:</code> message.<syntaxhighlight lang="smalltalk">
'foo.bar.baz.b64' copyReplaceAll: '.b64' with: <nowiki>''</nowiki>. "=> 'foo.bar.baz' "
'foo.bar.baz.b64' copyReplaceAll: '.b64' with: ''. "=> 'foo.bar.baz' "
</syntaxhighlight>
----Dr. Nicola Mingotti made this pange on this page on 19-Sep-2021. Tested in Cuis5.0-4834.image.
----Dr. Nicola Mingotti made this pange on this page on 19-Sep-2021. Tested in Cuis5.0-4834.image.

Latest revision as of 20:00, 12 May 2025

Problem. I have several file names ending with .zip.b64, I want to get rid of the .b64 part of the string.

Solution. Use the String >> copyReplaceAll: with: message.

'foo.bar.baz.b64' copyReplaceAll: '.b64' with: ''. "=> 'foo.bar.baz' "

Dr. Nicola Mingotti made this pange on this page on 19-Sep-2021. Tested in Cuis5.0-4834.image.