News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Scan for comma and move within a string

Started by newbieinfl, April 04, 2006, 02:30:51 PM

Previous topic - Next topic

newbieinfl

I know how to search for a comma within a string and even how to remove the comma (I've created and tested some programs and saw other posts on this) but I need to learn how to find a comma and move everything after the comma into a new string.  I'm puzzled.  Can anyone help please?

rags

Just create a buffer using GlobalAlloc of sufficient size, usually 128 -256 bytes for a normal string would do.
Use the handle from that allocation as a pointer to the new string.
Since you want everything after the comma in a new string, copy everthing from 1 byte past the comma, up to and including the terminating zero into the new string.
Dont forget to free the allocated buffer using GlobalFree when you are done using the new string.
Here are some links for GlobalAlloc and GlobalFree that may help.
GlobalAlloc
GlobalFree

Rags
God made Man, but the monkey applied the glue -DEVO

Mark Jones

Hi Newbie. How's Florida? :) Rags has some good ideas. You could also try stralloc and strfree, they are macros found in MASM32\macros\macros.asm. Use them as follows:


.data?
    lpBuffer DD ?
.code
    stralloc 256
    mov lpBuffer,eax
; lpBuffer is a memory offset where 256 bytes are (zeroed) and reserved.
    strfree lpBuffer


Note you can also do this:


.data?
    lpBuffer DB 256 dup(?)
.code


To manipulate strings on the byte-level, try this to get bytes into AL:


    mov esi,YourSourceStringOffset
    mov al,BYTE PTR [esi]
    inc esi
    mov al,BYTE PTR [esi]
    inc esi ;.... etc.


Here is a much nicer way to write this, but you must use ESI:


    mov esi,YourSourceStringOffset
    cld
    lodsb
    lodsb ;.... etc.


And to put bytes into a string:


    mov edi,YourDestinationStringOffset
    mov BYTE PTR [edi],al
    inc edi
    mov BYTE PTR [edi],al
    inc edi ;.... etc.


and the nicer version...


    mov edi,YourDestinationStringOffset
    cld
    stosb
    stosb ;.... etc.


Have fun. :8)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

newbieinfl

Thanks Mark!  This helps a lot!

Thank you to Rags as well, the sites did help.

-newbie

P.S.  Florida is great!  Not looking forward to hurricane season though.