is there any way of moving a pointer within a string as you do with a file, and then read a number of bytes etc.? i could just write the string to a temporary file i suppose, but that would be incredibly inefficient.

cheers.
skud.
Posted on 2001-09-13 11:17:47 by skud
perhaps it would be a good idea to read my string tutorial. you can downoad it from http://noperator.cjb.net

hope you like it. if you still have any questions, just post it here.

NOP-erator
Posted on 2001-09-13 11:27:08 by NOP-erator
thats exactly what i want!!

skud.
Posted on 2001-09-13 12:16:52 by skud
i need help again with strings :)

how do i move the file pointer?
there must be a way or else i have to read one byte however many times a want to skip forward which would make pretty ugly code :)

thanks.
skud.
Posted on 2001-09-25 13:10:51 by skud
If you really mean a file (which "move the file pointer" would indicate ;)),
why not have a look at SetFilePointer? Since you ask this question,
you probably don't have MSDN (or don't yet know how to browse it ;)),
so here's the prototype and a little explanation:


DWORD SetFilePointer(
HANDLE hFile, // handle of file
LONG lDistanceToMove, // number of bytes to move file pointer
PLONG lpDistanceToMoveHigh,
// pointer to high-order DWORD of
// distance to move
DWORD dwMoveMethod // how to move
);


The "high" can of course be set to NULL if you don't care about >4GB files.

the dwMoveMethod can be one of the following:
FILE_BEGIN : search from beginning of file
FILE_CURRENT : relative to current pointer
FILE_END : relative to end (subtracted)
Posted on 2001-09-25 16:12:50 by f0dder
sorry, i should have been more clear :(
yeah i know how to move a "SetFilePointer", but how can i do this within a string? i know how do load a byte from a string using a register that points at it, but if i want to skip past a given number of bytes then i have to load it loads of times. this cant be the only way....

sorry, im crap at explaining anything ;)
skud.
Posted on 2001-09-25 16:38:41 by skud
Ok, let's say you have ESI pointing to your string (something could
indicate it, since you feel you have to "load it loads of times", it
could sound like you're using lodsb). Well, why not just do a...


add esi, 5 ; to skip five chars in an ANSI string


If you have a string in a buffer and want a register to point to some
specific index in it, you can use lea:



lea esi, [buffer + 5] ; load esi with a pointer to the fifth char in the buffer


... and there's loads more. Just normal register stuff, nothing special
just because you're using strings :).
Posted on 2001-09-25 16:43:07 by f0dder
skud,

The general idea when working on a string in memory is to put its base address in one register and use another register as an index for how far into the string you are.

MOV ESI, StringAddress
XOR ECX, ECX

MOV AL, ; 1st byte

ADD ECX, 128 ; change offset with INDEX

MOV AL, ; byte at offset 128

You can design loop code to read the number of bytes you need from a given offset in the string and write it to another buffer if you need to do it.

Regards,

hutch@pbq.com.au
Posted on 2001-09-25 16:53:52 by hutch--
aha, i see. so the register you use as a pointer is just the number of bytes into the file you are - correct?

i now have the pointer where i want it in the string, but i want to read more than one byte? do i have to load it and append it to a buffer for however many bytes i want to read??

thanks a lot.
skud.
Posted on 2001-09-25 18:24:42 by skud
Skud, all this mixing of files and strings is quite confusing to me.
Are you messing with a 100% in-memory string, or are you also
doing file reading? :confused:

Hutches method uses a "base pointer" that always points to the
beginning of the string, and another string for the index.
This is often a nice method.

If you need to copy a portion of a string to another buffer, look
around for a string copying routine, I'm sure there's on in m32lib :).
Posted on 2001-09-25 18:29:01 by f0dder