i want to do something like this: Transcript show: '\n'. how?
相关问题
- Simple class definition error in smalltalk
- Which Smalltalk object should be passed to a C fun
- Squeak(smalltalk) subSrings ignores empty strings
- Smalltalk variables: why should I declare them?
- How to manage 2d array in Smalltalk?
相关文章
- Implementation Strategies for Object Orientation
- What is the difference between Seaside programmmin
- How to copy several Monticello commits from local
- Smalltalk ReferenceStream has problems with new in
- Is it possible to write shell command within Pharo
- Draw table in Pharo
- Double dispatch in Pharo
- How can I get all the methods in a Protocol?
From my (long) experience, missing character escapes are one of the few things that are missing in Smalltalk. For streaming, solutions using cr, tab etc. are ok.
However, if you need a particular control character in a string, this may be ugly and hard to read (using "streamContents:", or "withCRs" to add a newLine). Alternatively, you may want to use one of the (non-standard) string expansion mechanisms. For example, in VisualWorks or Smalltalk/X, you can write (if I remember correctly):
or even with printf-like slicing of other object's printStrings:
I guess, there is something similar in Squeak and V'Age as well.
But, be aware: these expansions are done at execution time. So you may encounter a penalty when heavily using them on many strings.
What I do as a convenience is add a method "line" to the String class:
Then you can just say
obj showSomething: 'Hello world!' line.
Or call it newline, endl, lf, etc...
The character itself can be reached as
Character cr
. So, you could also do this:But of course,
is way more elegant.
Use the following:
You can use it after a value via a cascade: