String 如何忽略输入键NASM win32
我需要忽略输入时的enter键,以便进一步将输入字符串与其他字符串进行比较。String 如何忽略输入键NASM win32,string,assembly,input,nasm,String,Assembly,Input,Nasm,我需要忽略输入时的enter键,以便进一步将输入字符串与其他字符串进行比较。 下面是代码输入和输出的片段 ;get output handle push dword STD_OUTPUT_HANDLE call GetStdHandle mov [hstdout],eax mov eax, 1000h ;get input handle push dword STD_INPUT_HANDLE call GetStdHandle
下面是代码输入和输出的片段
;get output handle
push dword STD_OUTPUT_HANDLE
call GetStdHandle
mov [hstdout],eax
mov eax, 1000h
;get input handle
push dword STD_INPUT_HANDLE
call GetStdHandle
mov [hstdin],eax
;Read
push 0
push actlen2 ;Pointer to a DWORD for number of characters read to be returned
push 11
push string
push dword [hstdin]
call ReadConsoleA
;Write
push 0
push actlen
push 11
push string
push dword [hstdout]
call WriteFile
字符串有换行符我想起来了
我刚刚编写了从字符串中删除0x0d和0x0a的代码
mov ecx,11; str len(and num of loop iterations)
mov eax,string
jmp ignore_enter
change_byte:
mov bl,0
mov byte[eax+ecx],bl;change byte to 0
ignore_enter:
cmp byte[eax+ecx], 0x0a; compare ecx byte of string with 0x0a
je change_byte; if equal change_byte
cmp byte[eax+ecx], 0x0D; compare ecx byte of string with 0x0d
je change_byte; if equal change_byte
loop ignore_enter
您有输入的长度,因此检查最后一个字符是否为换行符。如果是,请用
0
覆盖它。(或者无条件地这样做,假设它是一个换行符。或者,如果这个环境在输入时为您提供了一个2字节的换行符序列,则使用CR LF。)就像在中使用Linux系统调用一样;对你的WinAPI调用也有同样的想法。谢谢你的帮助,我发现IM noob,mb是一个愚蠢的解决方案,但它很有效