Smalltalk - Inserting a TAB character (Visual Works)
I'm having some trouble inserting a tab be开发者_Python百科tween two strings.
stringOne := 'Name'.
stringTwo := 'Address'.
I've tried:
info := stringOne, String tab, stringTwo.
or
info := stringOne, Character tab asString, stringTwo.
But none of those two messages are understood. I'm using Visual Works.
Goog gave you a way of making a String that included a tab
String with: Tab
and by yourself you discovered that Tab wasn't understood in VisualWorks and should be replaced by
Character tab
so put those 2 things together in a workspace evaluate to check it gives a String containing a tab Character
String with: Character tab
then use that in your concatenation
info := stringOne, (String with: Character tab), stringTwo.
(If you're going to do a lot of concatenation then use a WriteStream
not ,
)
I don't have Visual Works to check, but in IBM Smalltalk Tab
(note the case) is a tab character.
Maybe try this:
info := stringOne, Tab asString, stringTwo.
edit (re: your comment):
Okay, either Tab
is not the right name for a tab character, or your character class doesn't respond to asString
Try seeing what Tab class
gives you, if it answers "Character", then you just need to find out how to change a Character into a String in VisualWorks. If it doesn't answer "Character", then we haven't found the right name for tab characters in VisualWorks.
edit2:
I don't know the short way to turn a character into a string in Visual Works, so here is a solution that should work anyway. This is all that asString
would do anyway:
Since you'd probably want to use it multiple times, you can save it as a string,
tabString := String with: Tab.
info := stringOne, tabString, stringTwo
Its shortest to use macro expansion:
info := '<1s><T><2s>' expandMacrosWith: one with: two
WriteStream based solution (it's a bit more verbose, but scales nicely and you can use it in loops, like do:separatedBy)
ws := (String new:50) writeStream.
ws
nextPutAll: stringOne;
tab;
nextPutAll: stringTwo.
info := ws contents.
Or if you really like one liner code:
info := (String new writeStream) nextPutAll: stringOne; tab; nextPutAll: stringTwo; contents.
精彩评论