Tuesday, 10 September 2013

CString::find... iterative use issue?

CString::find... iterative use issue?

I'm using a CString to search a text block... here's my code:
// locate file name in dir listing
in = *buf;
i = in.Find("DOWNLD .DAT ");// find start of name, two spaces (0x20) as
delim
// size of search text here is 14
if (i == -1) return 0;
j = in.Find(' ',i);// now find next space char *after* file size...
// why don't I have to add to i here? There are spaces in my
search string.
if (j == -1) return 0;
fileSize = in.Mid((i+14),j-i);// extract file size string, note indexing
past found string
return atoi(fileSize.GetBuffer());
Here's what MSDN has to say about the return value of find: " Return Value
The zero-based index of the first character in this CString object that
matches the requested substring or characters; -1 if the substring or
character is not found."
Now the way I read this, I have to index past the string I found before
doing another find... but the way it actually works, I use the 'i'
returned before as the start position for a new search. I'm using this in
other places in my program, and I definitely have to index past it (when
using ::mid(), for instance)... I'd like to know why this is happening, if
by design or bug. The original string can be large; I've seen it near
300chars... is this the problem?

No comments:

Post a Comment