上一頁 | 目錄 | 下一頁
C.4 在字串裡尋找
; StrStr
; 輸入,堆棧頂 = 要尋找的字串
; 堆棧頂-1 = 在該字串中尋找
; 輸出,堆棧頂 (替換為字串剩餘部分)
; 不改變其它變量值。
;
; 用法:
; Push "this is a long ass string"
; Push "ass"
; Call StrStr
; Pop $R0
; ($R0 在這裡為 "ass string")
Function StrStr
Exch $R1 ; st=haystack,old$R1, $R1=needle
Exch ; st=old$R1,haystack
Exch $R2 ; st=old$R1,old$R2, $R2=haystack
Push $R3
Push $R4
Push $R5
Push $R6
StrLen $R3 $R1
StrLen $R6 $R2
StrCpy $R4 0
; $R1=needle
; $R2=haystack
; $R3=len(needle)
; $R4=cnt
; $R5=tmp
loop:
StrCpy $R5 $R2 $R3 $R4
StrCmp $R5 $R1 done
IntCmp $R4 $R6 done
IntOp $R4 $R4 + 1
Goto loop
done:
StrCpy $R1 $R2 "" $R4
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Exch $R1
FunctionEnd
上一頁 | 目錄 | 下一頁