格式化字符串数组以向用户显示
向非极客用户传达一个字符串中的一组字符串的最佳格式是什么?
我可以这样做:
Item1, Item2, Item3
但是当字符串包含空格和逗号时,这变得毫无意义。
我也可以这样做:
"Item1", "Item2", "Item3"
但是,我想避免转义数组元素,因为转义字符可能会让外行感到困惑。
编辑:我应该澄清我需要格式化字符串为一行。基本上,我有一个 .Net Winforms ListView 中显示的列表列表(尽管这个问题与语言无关)。我需要在 ListView 中列表名称旁边向用户显示列表的单行“快照”,以便他们大致了解列表包含的内容。
What is the best format to communicate an array of strings in one string to users who are not geeks?
I could do it like this:
Item1, Item2, Item3
But that becomes meaningless when the strings contain spaces and commas.
I could also do it this way:
"Item1", "Item2", "Item3"
However, I would like to avoid escaping the array elements because escaped characters can be confusing to the uninitiated.
Edit: I should have clarified that I need the formatted string to be one-line. Basically, I have a list of lists displayed in a .Net Winforms ListView (although this question is language-agnostic). I need to show the users a one-line "snapshot" of the list next to the list's name in the ListView, so they get a general idea of what the list contains.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以选择像管道 (|) 这样的字符,这些字符在外部程序中很少使用。它还用于表格的 wiki 标记,这对于熟悉 wiki 标记的人来说可能很直观。
You can pick a character like pipe (|) which are not used much outside programs. It also used in wiki markup for tables which may be intuitive to those who are familiar with wiki markup.
在 GUI 或彩色 TUI 中,单独为每个元素着色。在单色 TUI 中,添加几个空格并前进到每个单词之间的下一个制表符位置 (\t)。
In a GUI or color TUI, shade each element individually. In a monochrome TUI, add a couple of spaces and advance to the next tab position (\t) between each word.
使用 JSON,上面的列表将如下所示:
'[“项目1”,“项目2”,“项目3”]'。
这是明确的并且广泛使用的语法。只需稍微解释一下嵌套语法,他们可能就会明白。
当然,如果要在 UI 中显示,那么您不一定需要明确的语法,只要您希望它实际上看起来像针对最终用户的东西即可。在这种情况下,这将取决于您如何向用户显示它。
Using JSON, the above list would look like:
'["Item1", "Item2", "Item3"]'.
This is unambiguous and a syntax in widespread use. Just explain the nested syntax a little bit and they'll probably get it.
Of course, if this is to be displayed in a UI, then you don't necessarily want unambiguous syntax as much as you want it to actually look like something intended for the end user. In that case it would depend exactly how you are displaying this to the user.
将每个元素显示为表格中的一个单元格。
Display each element as a cell in a table.
每个字符串后面换行怎么样? :>
How about line breaks after each string? :>
将每个字符串显示在单独的行上,并带有行号:
这是人们在现实世界中编写列表的方式,你知道:)
Display each string on a separate line, with line numbers:
It's the way people write lists in the real world, y'know :)
使用某种印刷约定,例如粗体井号和字符串之间的空格。
牛奶#鸡蛋#面包#苹果#生菜#胡萝卜
Use some kind of typographical convention, for example a bold hashmark and space between strings.
milk # eggs # bread # apples # lettuce # carrots
CSV。因为非技术用户对分隔数据要做的第一件事就是将其导入电子表格。
CSV. Because the very first thing your non-technical user is going to do with delimited data is import it into a spreadsheet.