Show me the string, but max N. characters
In another programming language this may not be such an interesting function but in Smalltalk it is. Why? Because we have inspectors and we are used to see our data interactively. Now image the case you have an ordered collection of Strings, those strings might be email messages bodies or even book texts so, large stuff. If you open the Explorer it tries by default to show you all the string length, which in many cases it is not what you want and might slow you down.
Problem. We are dealing with long strings. When we print them we don't want by defaut to see the whole story, just the beginning and the end snippets are fine. How to do it ?
Solution. There is a builtin String>>contractTo:
that perform this simple operation for us, we don't need to re-define it ourselves.
"A foobar long string. "
s := 'sdf asdf asdfqwer qwe asd asdf asdf asdf asdf asdf asdf 123 123 1 '.
"let's have an idea of what is inside it ..."
s contractTo: 20. "=> 'sdf asdf ...3 123 1 '"
Dr. Nicola Mingotti last updated on 06-Sep-2021. Tested in Cuis5.0-4834.image.