【问题标题】:NSIS concatenating part of two stringsNSIS 连接两个字符串的一部分
【发布时间】:2011-06-01 14:23:20
【问题描述】:

我正在尝试在 NSIS 中将两个字符串合并在一起。我有两个字符串 2.1.3.0 和 0.0.0.27269,我想从它们创建的字符串是 2.1.3.27269

到目前为止我的尝试都没有奏效,这是我尝试过的:

;;$VERSION      is defined with 2.1.3.0
;;$FILEVERSION2 is defined with 0.0.0.27269

;;debug
DetailPrint ${VERSION}
DetailPrint ${FILEVERSION}

;;attempt, also it doesn't say what the variables $R0-$R2 are after values 
;;copied into them, is that normal?
StrCpy $R0 ${FILEVERSION2} 5 -5
StrCpy $R1 ${VERSION} -2 
StrCpy $R2 $R1"."$R0 

DetailPrint $R2 ;;this doesn't print a value, only prints "$R2"
!define FILEVERSION3 $R2

任何帮助都会很棒。 猎人

也在这里发布:http://forums.winamp.com/showthread.php?p=2777308#post2777308

【问题讨论】:

    标签: installation nsis nsis-mui


    【解决方案1】:

    要在 NSIS 中连接变量,您需要将它们用引号括起来。

    ;;$VERSION      is defined with 2.1.3.0
    ;;$FILEVERSION2 is defined with 0.0.0.27269
    
    ;;debug
    DetailPrint ${VERSION}
    DetailPrint ${FILEVERSION}
    
    StrCpy $R0 ${FILEVERSION2} 5 -5
    StrCpy $R1 ${VERSION} -2 
    
    ; This concatenates the strings together with a dot
    StrCpy $R2 "$R1.$R0" 
    
    DetailPrint $R2
    !define FILEVERSION3 $R2
    

    查看NSIS string functions list 也可能值得。与使用硬编码索引拆分字符串相比,获取字符串开头和结尾部分的函数可以使您的代码更加健壮。

    【讨论】:

    • 感谢您的帮助。我对此进行了测试,但它仍然无法正常工作,我相信的原因是我试图操纵由 !define 创建的变量。此方法适用于用户变量。我最终做的是编写一个小的可执行文件来在编译时将字符串传递给。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2011-02-07
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多