Hello,
Can someone please help me out with a small code on how to remove all spaces in an edit control (textbox).
I want to inline the ASM code into a c++ app, im not sure how to do this so any information is welcome too.
Thanks for any help.
Posted on 2005-08-12 18:47:08 by w00
In C++ you can very quicly write a subclassing code, which will be very efficient. No need to do that in ASM. While subclassed, forbid enetring the space.

Alternatively, here's the funcion which deletes any spaces from the buffer (get the buffer with GetWindowTextLength and GetWindowText).

(Please note that this is an ANSI-buffer function)

VOID __stdcall deleteSpaces(CHAR *buffer, ULONG buflen) {

? ? __asm {
? ? ? ? sub? ? ?eax, eax
? ? ? ? sub? ? ?ecx, ecx
? ? ? ? mov? ? ?edx,
? ? ? ? cmp? ? ?eax, // \ make sure that the string? ? |
? ? ? ? jz? ? ? retrn? ? ? ? ?// / is not empty? ? ? ? ? ? ? ? ?|--> you easily can delete these
? ? ? ? cmp? ? ?eax, edx? ? ? // \ make sure that the pointer? ?|--> 4 lines if you don't need them
? ? ? ? jz? ? ? retrn? ? ? ? ?// / is non-NULL? ? ? ? ? ? ? ? ? |
nxtiter:
? ? ? ? movzx? ?ebx, byte ptr
? ? ? ? inc? ? ?eax
? ? ? ? mov? ? ?, bl
? ? ? ? cmp? ? ?ebx, ' '
? ? ? ? jnz? ? ?notspace
? ? ? ? dec? ? ?ecx
notspace:
? ? ? ? inc? ? ?edx
? ? ? ? cmp? ? ?eax,
? ? ? ? jb? ? ? nxtiter
? ? ? ? or? ? ? ecx, ecx
? ? ? ? jz? ? ? retrn
? ? ? ? mov? ? ?byte ptr , 0
retrn:
? ?}
}


I'm kind of sleepy, so there might be some bugs here. It's a simple x86 function, so it should do the job in most cases. If you need to precess very large buffers, then try looking at MMX or integer SSE.
Posted on 2005-08-12 19:43:07 by ti_mo_n
Thanks, i tried your code but infortunatly it didnt work.
I've tried to call it like this

deleteSpaces(cText1,strlen(cText1));

cText1 contains the text and check the length of the string.
It doesnt seem to be remving any spaces. Any ideas why?
Posted on 2005-08-12 19:47:19 by w00
make sure that cText is a pointer to an ANSI string. make sure that strlen(cText) is equal to string's size. Run the debugger and check these values.
Posted on 2005-08-12 19:52:50 by ti_mo_n
Everything seems to be the way its suppose to be, i dont see  anything wrong.
Posted on 2005-08-12 20:01:24 by w00
try this code :
mov ecx,SIZEOF string
mov esi,(OFFSET string)-1
mov edi,esi
Label1: inc esi
inc edi
mov dl,BYTE PTR
mov BYTE PTR ,dl
cmp dl," "l
jne Label2
dec edi
Label2: dec ecx
jnz Label1
Posted on 2005-08-12 21:02:23 by NightWare
w00,

It depends on what you want to do, if its denial of spaces while you are typing into an edit control, you subclass the edit control and process the WM_CHAR message where you throw away the ascii 32 character and probably the TAB as well.

If you wat to clean out the spaces AFTER te data has been typed into an edit control, its a small algo that loops through the data writing back into the same buffer but excludes the spaces.

Just let us know what you are after.

Regards,

hutch at movsd dot com
Posted on 2005-08-12 21:42:17 by hutch--

w00,

It depends on what you want to do, if its denial of spaces while you are typing into an edit control, you subclass the edit control and process the WM_CHAR message where you throw away the ascii 32 character and probably the TAB as well.

If you wat to clean out the spaces AFTER te data has been typed into an edit control, its a small algo that loops through the data writing back into the same buffer but excludes the spaces.

Just let us know what you are after.

Regards,

hutch at movsd dot com


Its the second part, it should remove all spaces when the text has been typed into the edit control.
I havent tried NightWare idea yet, ill try that later on, but if you know a way than pls post yours too.
Posted on 2005-08-13 06:01:02 by w00
The following algo removes spaces and writes the result back to the same string buffer. The argument "txt" must be a zero terminated ANSI string.


remspace proc txt:DWORD

    mov ecx, txt
    mov edx, txt

  @@:
    mov al,
    add ecx, 1
    cmp al, 32      ; is it a space
    je @B
    mov , al
    add edx, 1
    test al, al    ; is AL zero
    jnz @B

    ret

remspace endp


Posted on 2005-08-13 07:22:31 by hutch--