Smalltalk - 插入 TAB 字符 (Visual Works)

发布于 2024-08-08 20:01:03 字数 305 浏览 2 评论 0原文

我在两个字符串之间插入制表符时遇到一些问题。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

此刻的回忆 2024-08-15 20:01:04

基于 WriteStream 的解决方案(它有点冗长,但可以很好地扩展,您可以在循环中使用它,例如 do:separatedBy)

ws := (String new:50) writeStream.
ws
    nextPutAll: stringOne;
    tab;
    nextPutAll: stringTwo.
info := ws contents.

或者如果您真的喜欢一个衬垫代码:

info := (String new writeStream) nextPutAll: stringOne; tab; nextPutAll: stringTwo; contents.

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.
跨年 2024-08-15 20:01:03

Goog 为您提供了一种制作包含选项卡的字符串的方法

String with: Tab

,您自己发现 Tab 在 VisualWorks 中无法理解,应该替换为

Character tab

因此将这两个东西放在一起 在工作区中评估以检查它给出一个包含制表符的字符串

String with: Character tab

,然后在您的串联中使用它

info := stringOne, (String with: Character tab), stringTwo.

(如果您要进行大量串联,则使用 WriteStream 而不是 ,

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

七堇年 2024-08-15 20:01:03

我没有 Visual Works 来检查,但在 IBM Smalltalk 中 Tab(注意大小写)是制表符。
也许试试这个:

info := stringOne, Tab asString, stringTwo.

编辑(回复:您的评论):

好的,要么 Tab 不是制表符的正确名称,或者您的字符类不响应 asString
尝试查看 Tab class 为您提供了什么,如果它回答“字符”,那么您只需要了解如何在 VisualWorks 中将字符更改为字符串即可。如果它没有回答“字符”,那么我们还没有在 VisualWorks 中找到制表符的正确名称。


edit2:

我不知道在 Visual Works 中将字符转换为字符串的简短方法,所以这里有一个应该可行的解决方案。这就是 asString 无论如何都会做的事情:
由于您可能想多次使用它,因此可以将其保存为字符串,

tabString := String with: Tab.
info := stringOne, tabString, stringTwo

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
天邊彩虹 2024-08-15 20:01:03

使用宏展开最短:

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

Its shortest to use macro expansion:

info := '<1s><T><2s>' expandMacrosWith: one with: two
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文