Hello
I have a little question about manipoulation on string.
I used the search function before posting but had no results.
I have a string
string1 db ",,,,,,",0
I read data from a "non-formated" file and I have to fill information in the string to write it in a "formatted" file.
Example, string1 become Name,Sex,DOB,Street,,, where name is always the name of the different record from the non-formatted file etc....
How can I fill the string correctly without parsing it with the count of , ??
Thanks in advance an sorry for my english, if it's not good, i'll explain it again.
Bros
Hello,
I have posted a sample on the genesys project that is able to solve that easily.
http://www.masm32.com/board/index.php?action=dlattach;topic=5290.0;id=2718
Use the limited function.
1)define the word you want to searche (search case can be sensitive or not)
2)define the list of caracters thare are able before and after the string
Take care with the limited lenght of the search.
any question ?,post it here.
ToutEnMasm
Hello
Thanks for the answer, but the problem is not searching the information, it works very well, it's for the insertion in the string1.
(in french)
ToutenASm, je pense que tu parles francais (de mémoire), en fait, j'ai un premier fichier, ou j'ai des données que je lis correctement, je dois les inserer dans un 2e, sous le format Nom,Sexe,DDN,rue,,,
Donc, j'ai créée une string string1 db ",,,,,,",0
Et comme le nom sera tjs a la même place, la rue aussi etc..., je me demandais comment faire pour remplir ma string1 sans devoir cahque fois compter le nombre de , avant d'inserer ma donnée. J'espere avoir été plus clair.
Thanks
Bros
Ok,
it's More clear in french :bdg.
To avoid the count of , before writing each string,best way is to put each string in separate buffers.
When you have all strings written in the buffers,don't use string1 db ",,,,,,",0
but a empty buffer and add each string to the buffer adding the , .For that you can use the lstrcat function or any other optimized function like this one.
.data
string1 db 256 dup (0)
.local pointeur:DWORD
lea eax,string1
mov pointeur,eax
invoke rtlzemory,add string1
invoke ConcaTene,pointeur,SADR("Name"),addr pointeur
invoke ConcaTene,pointeur,SADR(","),addr pointeur
invoke ConcaTene,pointeur,SADR("sex"),addr pointeur
.............. and so on
ToutEnMasm
;add two strings zero terminated
;additionne deux chaines terminées par zero
;write the pointer at end of phrase in padresse
;renvoi le pointeur en bout de chaine écrite dans padresse
;################################################################
ConcaTene PROC uses esi edi szSomme:DWORD, szAdd:DWORD ,padresse:DWORD
Local retour:DWORD
mov retour,0
;éviter un planté toujours néfaste
.if szSomme == 0 || szAdd == 0 || padresse == 0
jmp FindeConcaTene
.endif
mov esi,szAdd
mov edi,szSomme
cld
.LISTALL
@@:
.if byte ptr [edi] != 0 ;debut de chaine a augmenter
;aller en bout de chaine
inc edi
jmp @B
.endif
@@:
.NOLIST
.if byte ptr [esi] != 0
;recopier
movsb
jmp @B
.endif
mov al,0
mov [edi],al
;sauvegarder le pointeur de fin
mov esi,padresse
mov [esi],edi
mov retour,1
FindeConcaTene:
mov eax,retour
ret
ConcaTene endp
Bros you can write string into another string instead of a buffer but you have to add the linker switch /SECTION:.text,RWX so that the code section is read,write,executable. You also have to be sure that the new string you write in isn't longer than the original.
;test.asm
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
origstr db "originalstring",0
newstr db "newstring",0
.code
start:
invoke lstrcpy,addr origstr,addr newstr
invoke MessageBox,0,addr origstr,addr origstr,MB_OK
invoke ExitProcess,0
end start
;build.bat
\MASM32\BIN\ML /c /coff /Cp test.asm
\MASM32\BIN\link /SUBSYSTEM:WINDOWS /SECTION:.text,RWX test.obj
DEL *.OBJ
ECHO.
PAUSE
CLS
*edit just noticed thats not what you asked, :\ I need to stop drinking, oh well i'll leave this post
bros,
It will depend on what you want to do with the string data but first up I would look at a table driven version as you can routinely avoid characters you don't want and pick words on the basis of what characters you want. You need to work out what delimiters you require between words as well.
Just give us a wider sample range of the data you are processing and how you want it split up and someone may be able to help.
Hello
I have an idea this night (sometimes :p)
I think, I can also use a structure
Record STRUCT
Name db 25 dup (0)
Separator db ",",0
Sexe db 4 dup (0)
Separator db "',"0
City db 25 dup (0)
Record ENDS
And after copying all the data from teh struct to the buffer and write the buffer in a faile
No?
Bros,
just a tip, make sure the structure members are rounded up to the next 4 byte boundary as it aligns the data and you access in and out of the structure will be faster.
MyRecord STRUCT
Name db 28 dup (?)
Seperator db 4 dup (?)
etc ....
Hutch--,
That only works for DWORD accesses. Byte accesses are equally slow (you can't align a single byte anyway). :bg