我认为 scala 存在空格问题?
我正在尝试编写一个脚本来更快地生成 Lift 项目,但我相信我遇到了空白问题。
val strLiftGen = "mvn archetype:generate -U\-DarchetypeGroupId=net.liftweb\
-DarchetypeArtifactId=lift-archetype-blank\
-DarchetypeVersion=1.0\
-DremoteRepositories=http://scala-tools.org/repo-releases\-DgroupId=" + args(0)"\-DartifactId=" + args(1)"\-Dversion=1.0-SNAPSHOT */"
有人愿意用智慧的棍子打击新手并告诉我处理这样长绳子的聪明方法吗?
I'm trying to write a script to make generating Lift projects quicker but I believe i'm running into a white space issue.
val strLiftGen = "mvn archetype:generate -U\-DarchetypeGroupId=net.liftweb\
-DarchetypeArtifactId=lift-archetype-blank\
-DarchetypeVersion=1.0\
-DremoteRepositories=http://scala-tools.org/repo-releases\-DgroupId=" + args(0)"\-DartifactId=" + args(1)"\-Dversion=1.0-SNAPSHOT */"
Anyone care to hit the newb with the stick of wisdom and tell me a smart way of handling a long string like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的示例中存在多个语法错误(
"\ "
且在args(0)
和args(1)< 之后缺少
+
/code>.(复制粘贴错误?)。这是您可以执行的操作:然后,如何处理参数之间的空格取决于您将如何执行命令。
There are multiple syntax errors in your example (
"\ "
and missing+
afterargs(0)
andargs(1)
. (copy paste error?). Here is what you can do:Then how you handle whitespace between arguments depends a bit on how you'll execute the command.
如果您尝试获取出现某些反斜杠转义空格的字符串,则需要将反斜杠加倍。就目前情况而言,您所显示的内容实际上不会编译,因为单个反斜杠可能不会紧接在空格之前。
您可能需要使用三引号字符串,它会暂停所有反斜杠处理并允许嵌入换行符。在三引号字符串中,反斜杠永远不需要双倍。
If you're trying to get a string with some occurrences of a backslash-escaped space, then you need to double up the backslash. As it stands, what you've shown will not actually compile because a single backslash may not immediately precede a space.
You may want to use a triple-quoted string, which suspends all backslash processing and allows embedded newlines. Backslashes never need to be doubled in triple-quoted strings.