Well, generally the fastest way to do it is to loop through the string in a while loop, not relying on standard string routines. Some string library functions may be implemented in assembler on some platforms, generally printf/scanf/strtok and the like aren't.
the non-standard-library parser could be something like this:
// parse the source line into tokens[], returns the number of tokens found.
// note that some tokens may be empty.
int ParseLine( char* theSourceLine, const char* tokens[], int maxTokens )
{
currentToken = 0;
tokens[currentToken] = theSourceLine;
while (*theSourceLine)
{
if (*theSourceLine == ':')
{
*theSourceLine = 0; // null terminate this string
currentToken++;
if (currentToken >= maxTokens) return currentToken; // reached the limit; maybe return -1?
tokens[currentToken] = theSourceLine; // next token starts here
}
theSourceLine++;
}
return currentToken;
}
And then, if it were me, I'd have an array of the static strings to build up the final string:
static const char* finalStringConstants[MAX_FINAL_CONSTANTS] =
{
"CUST:NAME=",
"HT=",
"LT=",
<etc>
};
char outputLine[500]; // make it big enough
outputLine[0] = 0; // null terminate it to start
for (i = 0; i < MAX_FINAL_CONSTANTS; i++)
{
strcat(outputLine, finalStringConstants[i]);
strcat(outputLine, tokens[i] );
}
If that's not fast enough, you could store the token lengths when you are parsing them and use memcpy() rather than strcpy() in the final loop.