如何删除字符串中某个字符后的所有内容? [英] How do I remove everything after a certain character in a string?
本文介绍了如何删除字符串中某个字符后的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除'?'之后的字符串中的所有内容?到目前为止,我拥有的代码会搜索?".我如何从那里继续?
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?
这是我的代码.
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
推荐答案
您可以替换?"之后的所有内容.以零表示,因此?"之后的所有字符被删除":
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
请注意,搜索?"后,我们如何使用EDI和ECX的值.
Notice how we are using the values that EDI and ECX have after searching for "?".
这篇关于如何删除字符串中某个字符后的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文