i have a string stored in a buffer. towards the end of the string there is a - followed up with a few more characters. i need to trim off the - and all the following characters. how can i accomplish this? thanks smurf
If you know there is only one occurance of the '-' character, then read each character and compare with '-' (02Dh) when you find a match, replace the character with a 0 (zero).
If there might be more than one occurance, then get the length of the string and start at the end of the string and work backwards.
push edi lea edi,Buffer xor ecx,ecx .while byte ptr != 02Dh inc ecx .endw mov byte ptr,0 pop edi
This message was edited by anon, on 6/8/2001 3:48:28 PM
push edi invoke lstrln,addr Buffer mov ecx,eax lea edi,Buffer .while byte ptr != 02Dh dec ecx .endw mov byte ptr,0 pop edi
very simple: test_str db 'Smurf-searches',0 test_str_len equ $-offset test_str start_up: lea edi,test_str push edi ; save offset of test_str push 2Dh ; '-' ; requires less bytes pop eax @fnd: ; lets search.. scasb jnz @fnd dec edi ; fix pointer! pop ecx ; restore edit as ecx as ofs test_str add ecx,test_str_len ; add len sub ecx,edi ; subtract it from current ofs --> we get ; counter xor al,al ; zero it! rep stosb ; and cut off! ;) Happy coding!
thanks both Anon and MrVelox both of your methods worked great. smurf
Smurf, With non critical string manipulation there is another approach if you don't always want to write a dedicated string function to do what you need, the MASM32 library has a set of string functions that will do left string, mid string and right string functions and they are reasonably fast as well. With the delimiter "-", you can either scan the string to get its position or try the InString function if its a zero terminated string then use the szLeft function to read the number of bytes you want into another buffer. A well written dedicated function should be faster but there are many instances where you don't need to do it to get results. Regards, firstname.lastname@example.org