0

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

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

我怎样才能做到这一点?

4

1 回答 1

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

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

于 2013-01-21T16:58:29.463 回答