我想scala有一个空白问题?
我试图写一个脚本,使生成电梯项目更快,但我相信我遇到了一个空白问题我想scala有一个空白问题?,scala,command,whitespace,lift,Scala,Command,Whitespace,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="
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 */"
有没有人愿意用智慧之棒打新手,告诉我一个处理这样长字符串的聪明方法?如果你想得到一个出现了反斜杠转义空格的字符串,那么你需要将反斜杠加倍。目前,您所展示的内容实际上不会编译,因为单个反斜杠可能不会直接位于空格之前
您可能希望使用三重引号字符串,它将暂停所有反斜杠处理并允许嵌入换行符。反斜杠永远不需要在三倍引号的字符串中加倍。如果您试图获取出现反斜杠转义空格的字符串,则需要将反斜杠加倍。目前,您所展示的内容实际上不会编译,因为单个反斜杠可能不会直接位于空格之前
您可能希望使用三重引号字符串,它将暂停所有反斜杠处理并允许嵌入换行符。反斜杠永远不需要在三引号字符串中加倍。在您的示例中有多个语法错误(
“\”
,并且在args(0)
和args(1)
(复制粘贴错误?)之后缺少+
。您可以执行以下操作:
val strLiftGen =
"""mvn
archetype:generate
-U
-DarchetypeGroupId=net.liftweb
-DarchetypeArtifactId=lift-archetype-blank
-DarchetypeVersion=1.0
-DremoteRepositories=http://scala-tools.org/repo-releases
-DgroupId=%s
-DartifactId=%s
-Dversion=1.0-SNAPSHOT"""
val cleanStr = strLiftGen.replace('\n',' ').replaceAll("\\s{2,}"," ").trim
println(cleanStr.format(args(0), args(1)))
那么,如何处理参数之间的空白在一定程度上取决于您将如何执行命令。示例中存在多个语法错误(
“\”
和参数(0)
和参数(1)
(复制粘贴错误?)之后缺少+
。以下是您可以执行的操作:
val strLiftGen =
"""mvn
archetype:generate
-U
-DarchetypeGroupId=net.liftweb
-DarchetypeArtifactId=lift-archetype-blank
-DarchetypeVersion=1.0
-DremoteRepositories=http://scala-tools.org/repo-releases
-DgroupId=%s
-DartifactId=%s
-Dversion=1.0-SNAPSHOT"""
val cleanStr = strLiftGen.replace('\n',' ').replaceAll("\\s{2,}"," ").trim
println(cleanStr.format(args(0), args(1)))
那么你如何处理参数之间的空白部分取决于你将如何执行命令。酷,更干净!从来没有想到过!hrmm至于执行,我在LiftGenerate com.test测试,所以是groupID,然后是artifactId.酷,更干净!从来没有想到过!hrmm至于执行,我在LiftGenerate com.test测试,然后是groupID和artifactId。