Hi Logan,
Thanks for your help, the explanation is really excellent, especially
since the examples break down the problem.
But pls. see below :)
[SNIP]
OK, that wasn't too hard. But still, how do you split them?
Well, one way to do it is to modify origstr. (This assumes
origstr is writable memory!) You can just replace the first
character of the delimiter with a 0; that will cause everything
before it to be valid C string, because C strings are just
neverending sequences of characters except that they end if
one of the characters is a zero. You might worry about
overwriting something important, but since the 0 character is
just one byte, and since the delimiter has to be AT LEAST one
byte (how could it be shorter?) that's OK, as long as you
are OK with clobbering the delimiter.
[NG] I cant break up the line by replacing "|" with a "0", I need to
put both of the seperated fields into a structure & this cannot have
"0" at the end of either field.
[NG] If I hard code the first field with "me" and the 2nd with "0408
409 409" the call works fine, if I use your code to seperate the
fields nothing happens when I make the same call & there is no error
generated.
[NG] I believe that is because the 1st field has the "0" now, and this
breaks the structure I feed the 2 fields into.
But what about the second string? Well, it already has a NULL
terminator at the end of it, so it's *already* a valid string.
So all you need to do is make sure you have a pointer to the
beginning of it, and you can use it as a string.
So, you can find the first string and advance to the second
with a function like this (note that it's virtually identical
to the above function, except I've added a few lines.
Char *BreakUpString (Char *origstr)
{
const Char *delimiter = " | ";
Int32 delimiterlen = StrLen (delimiter);
Char *firststart;
Char *delimiterstart;
Char *secondstart;
// the first string starts at the beginning
firststart = origstr;
// StrStr() will just tell us where the delimiter starts
delimiterstart = StrStr (origstr, delimiter);
if (delimiterstart == NULL)
{
// we have to return something to signal an error
return NULL;
}
// the second strings starts right after the delimiter
secondstart = delimiterstart + StrLen (delimiter);
// add a null terminator after first string
*delimiterstart = 0;
// return the start of the second string
return (secondstart);
}
[NG] I tried changing this routine to not have the "0", but I didnt
get any joy, this seems so trivial but it break the app.
[NG] How can I removed the "0" from the 1st fields after they are
seperated, or not replace "|" with the "0" and still have the 2 fields
?
[SNIP]
Thanks in advance.
--
..-_|\ Nigel Grant
/ OZ \ Uni. SA
\ _.--._ / PO Box 185 Adelaide
v South Australia 5096
.) .)
http://geocities.com/ngrant_com
Smile its free
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/