如何删除字符串中某个字符后的所有内容?

How do I remove everything after a certain character in a string?

如何删除字符串中“?”之后的所有内容?到目前为止我的代码搜索“?”。我该如何继续?

这是我的代码。

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

你可以替换“?”后面的所有内容由零,所以“?”之后的所有字符已经 "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

请注意我们如何使用搜索“?”后 EDI 和 ECX 的值。