How do I remove everything after a certain charact

2019-05-31 22:25发布

How do I remove everything in the string after the '?' ? The code I have so far searches for the '?'. How do I proceed from there?

This is my code.

INCLUDE Irvine32.inc

.data
source BYTE "Is this a string? Enter y for yes, and n for no",0

.code
main PROC

mov edi, OFFSET source
mov al, '?'                  ; search for ?
mov ecx, LENGTHOF source
cld
repne scasb       ; repeat while not equal
jnz quit
dec edi           ; edi points to ?

end main

1条回答
疯言疯语
2楼-- · 2019-05-31 22:56

You can replace everything after the "?" by zeroes, so all the characters after "?" are been "removed" :

INCLUDE Irvine32.inc

.data
source BYTE "Is this a string? Enter y for yes, and n for no",0

.code
main PROC

mov edi, OFFSET source
mov al, '?'                  ; search for ?
mov ecx, LENGTHOF source
cld
repne scasb       ; repeat while not equal
jnz quit
dec edi           ; edi points to ?

;REPLACE ALL CHARACTERS BY "AL" (ZERO) STARTING WHERE "EDI" WAS AND
;FINISH WHEN "ECX" == 0.
mov al, 0         ;<=====================================
repne stosb       ;<=====================================

end main

Notice how we are using the values that EDI and ECX have after searching for "?".

查看更多
登录 后发表回答