Jump to content

Stringformat


jpm
 Share

Recommended Posts

I want to implement a StringFormat("printf format", var1, ... varn)

How can I generate the

sprintf(szBuffer, vParams[0].szValue(),vParams[1].szValue(),

vParams[2].szValue(), vParams[3].szValue(),

vParams[4].szValue(), vParams[5].szValue());

the above is only working if the var's are strings and a fixed number of parameter

I cannot manage to have the type of the var used.

I would prefer a variable number of parameters as in sprintf

Thanks for the help :whistle:

Link to comment
Share on other sites

  • Administrators

Just have a high optional number of parameters, like {1, 32}. Then you can see how many parameters you were actually passed with iNumParams.

Use vParams[n].isNumber and .isString to see what type of param was passed.

Link to comment
Share on other sites

Just have a high optional number of parameters, like {1, 32}.  Then you can see how many parameters you were actually passed with iNumParams.

Use vParams[n].isNumber and .isString to see what type of param was passed.

Jon,

that does solve the type of parameter sprintf is requesting.

I cerlainly need to split the "printf format" at each reference and concataned the different piece.

I don't know how sprintf is implemented but they did it perhaps with the help of the compiler

So I will split/concatanate

Thanks

Link to comment
Share on other sites

I've seen an implementation of a sprintf-like function that did something along the lines of look for a % and when that's found, enter a case structure and compare the next character to 'c', 's', 'd', 'f' et cetera. If it matched, then it does the necessary type conversions or whatever. Otherwise, the characters are just concactenated to the string it's making. The function is long and ugly, but it's probably more meticulous to write than it is anything else. However, the version I saw was optimized for some specific use (I can't remember exactly what).

Link to comment
Share on other sites

I've seen an implementation of a sprintf-like function that did something along the lines of look for a % and when that's found, enter a case structure and compare the next character to 'c', 's', 'd', 'f' et cetera.  If it matched, then it does the necessary type conversions or whatever.  Otherwise, the characters are just concactenated to the string it's making.  The function is long and ugly, but it's probably more meticulous to write than it is anything else.  However, the version I saw was optimized for some specific use (I can't remember exactly what).

Thanks Valik,

That almost what I described. I think I have an implementation for tomorrow

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...