hello
i want to delete a bit of the returning string from a function...
i got something like "hello bla bla - _bj"
i want to delete "- _bj" in my string...
how? i alwasy have "- _bj" in the end of the string...
Posted on 2003-11-20 15:05:41 by bj1500
Will this string be placed in memory where you can operate on it or is this a question about some API function?
Posted on 2003-11-20 15:22:07 by mrgone

helllo
i want to delete a bit of the returning string from a function...
i got something like "hello bla bla - _bj"
i want to delete "- _bj" in my string...
how? i alwasy have "- _bj" in the end of the string...


You can use the lstrcpyn function. You can do something like this.

 

.data

string db "hello bla bla - _bj ", 0

.code
start:
invoke lstrcpyn, addr string, addr string, sizeof string - 2
.....
Posted on 2003-11-20 15:27:18 by Odyssey
To "delete" the last n bytes of a zero terminated string, put a zero n bytes before the end!



invoke strlen, ADDR my_string
lea eax, [eax + my_string - 5]
mov BYTE PTR [eax], 0


If you want to delete a section of the string that is in the middle, then you must copy the bytes like so:


lea esi, [my_string + 8]
lea edi, [my_string + 4]

@@:
lodsb
or al, al
stosb
jnz @B

Because the source is after the destination, the copy will over-write as it increments.

Mirno
Posted on 2003-11-20 17:44:39 by Mirno
bj1500,

Below is an algo that I have written for the next release of the MASM32 library. It is designed to remove substrings from source strings. You can either use 2 buffers if you want to preserve the original string or you can use the same address in both buffers if overwriting the original is OK.

It is not yet exhaustively tested but it appears to be working OK.

src = source string
dst = destination buffer
remv = the address of the zero terminated substring you want to remove from the source string.

If you are using it with MASM, slightly rename the algo as the name is being used in the next MASM32 library and you will have name clashes if you end up using the later version.




; ?????????????????????????????????????????????????????????????????????????

align 4

szRemove proc src:DWORD,dst:DWORD,remv:DWORD

push esi
push edi

mov edx, remv
mov ah, [edx] ; 1st remv char in AH

mov esi, src
mov edi, dst
sub esi, 1

; --------------------------------------------------------

prescan:
add esi, 1
scanloop:
cmp [esi], ah ; test for "remv" start char
je presub
backin:
mov al, [esi]
mov [edi], al
cmp BYTE PTR [edi], 0 ; exit when zero terminator
je szrOut ; has been written
add edi, 1
jmp prescan

align 4
presub:
xor ecx, ecx
subloop:
mov al, [esi+ecx]
cmp al, [edx+ecx]
jne backin ; jump back on mismatch
add ecx, 1
cmp BYTE PTR [edx+ecx], 0 ; test if next byte is zero
jne subloop

add esi, ecx ; add len of remv string to ESI
jmp scanloop

; --------------------------------------------------------

szrOut:

pop edi
pop esi

mov eax, dst ; return the destination address

ret

szRemove endp

; ?????????????????????????????????????????????????????????????????????????


Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2003-11-20 18:04:22 by hutch--

hello
i want to delete a bit of the returning string from a function...
i got something like "hello bla bla - _bj"
i want to delete "- _bj" in my string...
how? i alwasy have "- _bj" in the end of the string...


You might look at the str.delete function in the HLA Standard Library.
If you're deleting text at the end of the string, then (as others have
noted) just store a zero over the first char you want to delete (assuming
the use of zero-terminated strings). If the stuff you want to delete is
in the middle of the string, then you do the equivalent of an strcpy
from the last part of the string you want to keep over the top of the
characters you want to delete. Again, look at the source code
for the HLA str.delete function for details.
Cheers,
Randy Hyde
Posted on 2003-11-20 22:16:20 by rhyde
hello, thx for all help
this solved my problem:
 

invoke lstrlen,ADDR buf
lea eax, [eax + buf - 8]
mov BYTE PTR [eax], 0
Posted on 2003-11-21 04:12:16 by bj1500