The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: 2-Bit Chip on August 20, 2009, 12:23:46 AM

Title: Split A String
Post by: 2-Bit Chip on August 20, 2009, 12:23:46 AM
Would there be any macros for this?
Title: Re: Split A String
Post by: dedndave on August 20, 2009, 12:49:04 AM
there are quite a few macros for strings in the masm32 package
see the help file named "masm32\help\hlhelp.chm" - look under "macro catagories" - "string macros"
Title: Re: Split A String
Post by: 2-Bit Chip on August 20, 2009, 01:30:21 AM
Quote from: dedndave on August 20, 2009, 12:49:04 AM
there are quite a few macros for strings in the masm32 package
see the help file named "masm32\help\hlhelp.chm" - look under "macro catagories" - "string macros"

None for splitting a string. ::)
Title: Re: Split A String
Post by: dedndave on August 20, 2009, 01:33:30 AM
well - i think left$ and right$ might be useful
i sometimes use them with uhex$ because uhex$ only accepts a dword register and i may want a byte or word

print right$(uhex$(eax),4)

that essentially takes the right-hand 4 characters of the uhex$ string and makes a new string out of it
i could use them together

print left$(right$(uhex$(eax),4),2)

that would show me the hex value of AH

someString db 'hello world',0

right$(left$(ADDR someString,5),1)
that would return the address of a new string in eax = "o",0
Title: Re: Split A String
Post by: hutch-- on August 20, 2009, 05:40:12 AM
2 bit,

Depends of what you want to split and by what criterion. Tell us what you are trying to do and we may be able to help you.
Title: Re: Split A String
Post by: 2-Bit Chip on August 20, 2009, 07:09:49 AM
Split a string in half.

hello, there

I will not know how long the first section (before comma) will be.
Title: Re: Split A String
Post by: hutch-- on August 20, 2009, 08:06:23 AM
Its probably a very simple algo you need, read everything up to the ",", place it in one buffer, read everything up to the end of the string AFTER the "," into a second buffer. If you can modify the original, overwrite the first "," with a zero. Use the original address for the first then use the address of the character following the "," as the second address.

That is probably the fastest way to do it.
Title: Re: Split A String
Post by: 2-Bit Chip on August 20, 2009, 06:17:43 PM
Alright, thank you hutch.