NSIS - 从字符串中删除前导和尾随空格

时间:2013-01-21 07:23:02

标签: nsis

我想在NSIS中修剪我的文本框值,因为我使用了以下链接

http://nsis.sourceforge.net/Remove_leading_and_trailing_whitespaces_from_a_string  我的解决方案的问题是,上面的示例删除整个文本,然后是文本说例子我的文字就像这个“名字”。当我调用trim方法时,它会删除整个名称本身,并将结果显示为“First”。但我想只删除前导和尾随空格。不是中间空间。

我怎样才能实现这个目标?

1 个答案:

答案 0 :(得分:0)

适合我:

Function Trim
    Exch $R1 ; Original string
    Push $R2
Loop:
    StrCpy $R2 "$R1" 1
    StrCmp "$R2" " " TrimLeft
    StrCmp "$R2" "$\r" TrimLeft
    StrCmp "$R2" "$\n" TrimLeft
    StrCmp "$R2" "$\t" TrimLeft
    GoTo Loop2
TrimLeft:
    StrCpy $R1 "$R1" "" 1
    Goto Loop
Loop2:
    StrCpy $R2 "$R1" 1 -1
    StrCmp "$R2" " " TrimRight
    StrCmp "$R2" "$\r" TrimRight
    StrCmp "$R2" "$\n" TrimRight
    StrCmp "$R2" "$\t" TrimRight
    GoTo Done
TrimRight:
    StrCpy $R1 "$R1" -1
    Goto Loop2
Done:
    Pop $R2
    Exch $R1
FunctionEnd
!define Trim "!insertmacro Trim"
 !macro Trim ResultVar String
  Push "${String}"
  Call Trim
  Pop "${ResultVar}"
!macroend


Section

${Trim} $0 " First Name "
MessageBox mb_ok "|$0|"

SectionEnd

也许您可以编辑您的问题以包含失败的示例代码?