views:

134

answers:

3

I'm having some trouble inserting a tab between 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.

+2  A: 

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
Goog
#asString, message not understood. It doesn't work on Visual Works. Hmmm I can't even find it online
It answers to Character. So Character tab is correct, but there is not method to convert it to string. It's ok my stuff will just look a little unaligned. Thanks though
Ah okay well, then it's just down to the specifics of VisualWorks, which I don't know about. I have however added a longer solution that should hopefully work...
Goog
+1  A: 

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 ,)

igouy
it is at least dangerous to use the comma operator without precaution. And there's a shortcut for String with:, it's called asString. So I'd rewrite this as stringOne copy , Character tab asString , stringTwo
nes1983
+1  A: 

Its shortest to use macro expansion:

info := '<1s><T><2s>' expandMacrosWith: one with: two
Adrian