I know how to add two strings, and find the length and stuff using API, but how do I delete a string?
Posted on 2002-09-11 18:29:17 by CyberGuy
Easiest way is to copy bytewise from one buffer to another and leave out the characters (bytes) you don't want.

Posted on 2002-09-12 00:39:46 by bazik
easy, just put a zero at the start of the string...

.data
blabla db "stringstringstring",0

.code
lea eax, blabla
mov byte ptr , 0

in assembler there is no such thing like a "string"... don't look at it in a c
perspective, in asm "strings" are nothing else as an array of bytes. so
you can't simple "delete" a string but you can trick the apis.

if the size of the string changes (no fixed lenght) at runtime then you can
dynamicaly allocate a data-block for it... now this situation is a little bit
different since in this case you CAN delete the memory block after you're
done processing or whatever the hell you may doing---
Posted on 2002-09-12 02:54:19 by mob
that works to delete the whole string, or replace one character but how would you just delete certain characters?
Posted on 2002-09-12 13:45:55 by CyberGuy

that works to delete the whole string, or replace one character but how would you just delete certain characters?


Read my reply above.
Posted on 2002-09-12 16:02:48 by bazik
I'm a newbie to asm, so sorry I didn't really understand how to do that :(
Posted on 2002-09-12 18:21:44 by CyberGuy
Read some (more?) stuff about assembly programming and then you think of strings as CERTAIN byte values in some address on the memory (like the string "0123" would be on memory as:

001122: 30 31 32 33 ...

where each HEX number is one byte value. If it is a zero terminated string, the next byte ( BYTE [001126] ) would be NULL, or 0h.

I recomend the file attached on http://www.asmcommunity.net/board/showthread.php?postid=57431.msg57431

Laterz.....
Posted on 2002-09-12 21:12:51 by wicr0s0ft
...and what did you mean with

that works to delete the whole string, or replace one character but how would you just delete certain characters?

even in vb you can not simply "delete characters" ... but you can use these
string api's to cut and copy a string...

lstrcat
lstrcpy
lstrcpyn

also look up these in your api ref:

lstrcmp
lstrcmpi
lstrlen

but since you are programing in ASSEMBLER i would sit down and learn how to access
the memory or what the opcodes stos/movs/lods mean... good luck anyway
Posted on 2002-09-13 03:53:50 by mob
CyberGuy,

If removing a part of a string is what you are after, ther is no standard function in the APIs to do it so you will have to write it yourself.

If it is characters at a specified location, you just copy to that location, skip the ones you want then copy the rest.

If its a search and remove operation, you will need to find the text to remove and do the same thing, copy up to its start, skip the length of the search pattern and copy the rest.

You could write a dedicated function for it if you are familiar with string manipulation in assembler, it would be no big deal to do.

Regards,

huch@movsd.com
Posted on 2002-09-13 04:50:20 by hutch--
Thanks to all of you guys, I get it now, Thanks. Sorry for making you go through all of this trouble to explain it to me, but I have two more questions, how would you convert and a number(byte, integer, etc) into a string? And, let's say you have a string 'ABCDEFG', and you only want to copy 'DEF', how would you do that? I would have to copy only the specific 3 bytes. I mean, I can copy it using lstrcpyn but how could I just get those 3 characters, since its in the middle its harder.

Could someone try to make a function like strdel(source,index,length)?
Posted on 2002-09-13 15:38:35 by CyberGuy
I have a function like that: CopyMemory (since the Win32 API doesn't have it). It first uses cStrLen (another of my functions) to get the length if you supply -1 for the length.

Here's how I implemented them:
cStrLen uses repnz scasb with al=0. It returns the length in ecx (more convienient than eax.)
CopyMemory uses rep movsb.

They total under 20 lines of code.

You would then use as follows:

MyStr db 'ABCDEF'

Dest rb 4

stdcall CopyMemory, MyStr+3, Dest, 3

-----------------------------------

Use the search function to find how to convert a Native Format number (Hex, Bin, etc) into an ASCII(z) string.
Posted on 2002-09-19 01:25:33 by eet_1024

Could someone try to make a function like strdel(source,index,length)?


Don't you think it would be a great learning experience if you write one? :)
Posted on 2002-09-19 02:05:04 by bazik