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

烂漫一生 提交于 2020-01-03 03:28:14

问题


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:


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 "?".



来源:https://stackoverflow.com/questions/37036950/how-do-i-remove-everything-after-a-certain-character-in-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!