在NIS语言中如何从字符串中只获取jre1.8.0_91?
String "C:\Program Files\Java\jre1.8.0_91"
发布于 2018-06-08 21:52:47
@Vinod希望您使用的是最新版本的NSIS。此外,可以使用NSIS (nsh.zip)包含最新版本的标头,也可以包含WordFind函数
!include "WordFunc.nsh"
在您的.nsi脚本中。
这样,您就可以使用WordFind函数从文件路径(本例中为C:\Program Files\Java\jre1.8.0_91 )中提取文件名(本例中为jre1.8.0_91),如下所示:
${WordFind} "${FilePath}" "\" "-1" $R0
$R0将包含文件路径中的最后一个“单词”(jre1.8.0_91)。
这是通过使用反斜杠("\")作为字符串的分隔符,并选择第一个单词,从字符串末尾向后计数("-1")来实现的。
发布于 2018-06-09 03:34:30
NSIS中的每个字符串操作都可以使用StrCpy
、StrCmp
和StrLen
进行编码。您可以尝试如下所示:
!macro PathGetFilename path outvar
Push "${path}"
Call PathGetFilename
Pop ${outvar}
!macroend
Function PathGetFilename
Exch $1
Push $2
Push $3
StrCpy $2 ""
loop:
IntOp $2 $2 - 1
StrCpy $0 $1 1 $2
StrCmp $0 "" done
StrCmp $0 '\' +3
StrCmp $0 '/' +2
Goto loop
IntOp $2 $2 + 1
IntCmp $2 0 "" +2 +2
StrCpy $1 "" ; Ended with slash, return empty string
StrCpy $1 $1 "" $2
done:
Pop $3
Pop $2
Exch $1
FunctionEnd
Section
!insertmacro PathGetFilename "c:\test" $0
DetailPrint |$0|
!insertmacro PathGetFilename "c:\foo/bar" $0
DetailPrint |$0|
!insertmacro PathGetFilename "nameonly" $0
DetailPrint |$0|
!insertmacro PathGetFilename "\endslash\" $0
DetailPrint |$0|
SectionEnd
https://stackoverflow.com/questions/50761224
复制相似问题