如何在 CSH 中拆分字符串?
例如,我想用逗号作为分隔符分割“一,二,三”,并使用循环分别处理结果的三个子字符串。
For example, I want to split "one,two,three" with comma as delimiter and use a loop to process the resulted three substring separately.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
比当前提出的解决方案更简单的解决方案涉及使用内置替换修饰符 - 在这种情况下没有必要或理由浪费地使用循环或外部命令替换:
() 创建一个列表,:s 是替换修饰符和 :as 根据需要多次重复替换。
此外,t/csh 不需要引用裸字符串,也不需要引用不需要强制求值的变量。
A simpler solution than the current one presented involves using the built-in substitution modifer -- there is no need or reason to wastefully use a loop or external command substitution in this instance:
() creates a list, the :s is the substitution modifier and :as repeats the subtitution as many times as needed.
Furthermore, t/csh does not require quoting of bare strings, nor variables that do not require forced evaluation.
例如:
但请考虑 csh 是否适合您正在做的任何工作:
http://www.bmsc.washington.edu/people/merritt/text/cshbad.txt
For example:
But consider whether csh is the right tool for whatever job you're doing:
http://www.bmsc.washington.edu/people/merritt/text/cshbad.txt