Smalltalk - 插入 TAB 字符 (Visual Works)
我在两个字符串之间插入制表符时遇到一些问题。
stringOne := 'Name'.
stringTwo := 'Address'.
我已经尝试过:
info := stringOne, String tab, stringTwo.
或
info := stringOne, Character tab asString, stringTwo.
但这两条消息都不被理解。我正在使用视觉作品。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
基于 WriteStream 的解决方案(它有点冗长,但可以很好地扩展,您可以在循环中使用它,例如 do:separatedBy)
或者如果您真的喜欢一个衬垫代码:
WriteStream based solution (it's a bit more verbose, but scales nicely and you can use it in loops, like do:separatedBy)
Or if you really like one liner code:
Goog 为您提供了一种制作包含选项卡的字符串的方法
,您自己发现 Tab 在 VisualWorks 中无法理解,应该替换为
因此将这两个东西放在一起 在工作区中评估以检查它给出一个包含制表符的字符串
,然后在您的串联中使用它
(如果您要进行大量串联,则使用
WriteStream
而不是,
)Goog gave you a way of making a String that included a tab
and by yourself you discovered that Tab wasn't understood in VisualWorks and should be replaced by
so put those 2 things together in a workspace evaluate to check it gives a String containing a tab Character
then use that in your concatenation
(If you're going to do a lot of concatenation then use a
WriteStream
not,
)我没有 Visual Works 来检查,但在 IBM Smalltalk 中
Tab
(注意大小写)是制表符。也许试试这个:
编辑(回复:您的评论):
好的,要么
Tab
不是制表符的正确名称,或者您的字符类不响应asString
尝试查看
Tab class
为您提供了什么,如果它回答“字符”,那么您只需要了解如何在 VisualWorks 中将字符更改为字符串即可。如果它没有回答“字符”,那么我们还没有在 VisualWorks 中找到制表符的正确名称。edit2:
我不知道在 Visual Works 中将字符转换为字符串的简短方法,所以这里有一个应该可行的解决方案。这就是
asString
无论如何都会做的事情:由于您可能想多次使用它,因此可以将其保存为字符串,
I don't have Visual Works to check, but in IBM Smalltalk
Tab
(note the case) is a tab character.Maybe try this:
edit (re: your comment):
Okay, either
Tab
is not the right name for a tab character, or your character class doesn't respond toasString
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,
使用宏展开最短:
Its shortest to use macro expansion: