I was wondering if there was any way to isolate a piece of text within a string. I am trying to make a Task Manager in that instead of displaying something like:


or something, it would just display simply


is there anyway to check if a certain string exists in another string? Something like sscanf() but in terms of WinAPI? Or simply, how do you locate a string in a piece of text in WinAPI?


any help will be greatly appreciated :)
Posted on 2003-03-16 18:15:07 by Drocon
Not sure what you mean, but I don't think there is API for substring search. You could use this though:
strstr proc pszHaystack:PTR BYTE, pszNeedle:PTR BYTE, dwCaseSensitive:DWORD

push esi
push edi
xor eax, eax
xor ecx, ecx
xor edx, edx
mov esi, [pszHaystack]
mov edi, [pszNeedle]
@@char: mov al, byte ptr [esi]
mov ah, byte ptr [edi]
cmp [dwCaseSensitive], 0
jne @@cmp1
cmp al, "Z"
ja @@cmp0
cmp al, "A"
jb @@cmp0
add al, 32
@@cmp0: cmp [dwCaseSensitive], 0
jne @@cmp1
cmp ah, "Z"
ja @@cmp1
cmp ah, "A"
jb @@cmp1
add ah, 32
@@cmp1: cmp al, ah
jne @@next
inc ecx
mov eax, esi
inc edi
inc esi
inc eax
cmp byte ptr [esi], 0
je @@zero
cmp byte ptr [edi], 0
je @@quit
jmp @@char
@@zero: mov dl, byte ptr [edi]
cmp dl, byte ptr [esi]
je @@quit
xor eax, eax
xor ecx, ecx
jmp @@quit
@@next: mov edi, [pszNeedle]
test ecx, ecx
setz dl
add esi, edx
xor ecx, ecx
xor eax, eax
cmp byte ptr [esi], 0
jne @@char
@@quit: sub eax, ecx
pop edi
pop esi
strstr endp
Posted on 2003-03-16 18:38:41 by comrade
hmm, could i have a example of that procedure of yours comrade?

Posted on 2003-03-16 18:46:25 by Drocon
what i would probably do would be to search the entire string for only the "\" character, and the last occurance found would reveal the start of the substring you're searching for. then you could search for the "." character, which would mark the end of it, and you know the extension is always 3 bytes long, so you could just copy those easily. that would be kindda case-specific though.
Posted on 2003-03-18 21:14:36 by Kobra

With a substring, it depends on how you wish to identify it. The trailing filename is identified by the location of the last "\" so if you take Kobra's suggestion and scan for it, once you have the location, just write from the next byte until the zero terminator to another buffer and you have the trailing filename by itself.

There is an algo in the MASM32 library that does this function called "NameFromPath". You could use the different algos in the MASM32 library to write a version of your own if you need to do something different.


Posted on 2003-03-19 02:49:30 by hutch--