2013-01-21 80 views
0

我要修剪在NSIS我的文本框的值尾部空格,對於我已經使用下面的鏈接NSIS - 刪除的前導和串

http://nsis.sourceforge.net/Remove_leading_and_trailing_whitespaces_from_a_string 問題,我的溶液,例如上述刪除整個文本隨後通過文字說例子我的文字是這樣的「名字」。當我調用修剪方法時,它會刪除整個名稱本身並將結果顯示爲「第一個」。但是我想刪除只有前導和尾隨的空白。不是中間空間。

我該如何做到這一點?

回答

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 

也許你可以編輯你的問題,包括失敗的例子代碼?