Home All Groups Group Topic Archive Search About

"printf" style string method?

Author
30 Jun 2005 3:20 PM
Robin Tucker
Given the need to (possibly) alter the position of various elements in a
string due to localisation, is it possible to build a string using a
"printf" style function, such that the source string can also contain the
position of the elements to follow?  Eg. :

    printf ( "Your database is marked as version %d, but this client
requires a schema version %d" or later", dbVersion, dbRequiredVersion);

where in another locale, we might rearrange this sentance to something like:

    printf ( "Your database is marked %d as the version, but this client
requires a %d schema version or later", dbVersion, dbRequiredVersion);



ie: the grammatical rules for different languages are not neccessarily those
of English.  At present, I've got resource strings that are just breaking up
the sentances, which I recombine with things like:


    theString = "Your database is marked as version " + dbVersion.ToString +
", but this client requires a schema version " + dbRequiredVersion.ToString



Now, although these fragments can be translated, I don't see how it's
possible to alter the ordering as might be required - .....



Is there a method or algorithm analogous to printf I can use in VB?



Cheers



Robin

Author
30 Jun 2005 3:33 PM
Armin Zingler
Show quote Hide quote
"Robin Tucker" <idontwanttobespammedanymore@reallyidont.com> schrieb
>
> Given the need to (possibly) alter the position of various elements
> in a string due to localisation, is it possible to build a string
> using a "printf" style function, such that the source string can
> also contain the position of the elements to follow?  Eg. :
>
>    printf ( "Your database is marked as version %d, but this client
> requires a schema version %d" or later", dbVersion,
> dbRequiredVersion);
>
> where in another locale, we might rearrange this sentance to
> something like:
>
>    printf ( "Your database is marked %d as the version, but this
> client requires a %d schema version or later", dbVersion,
> dbRequiredVersion);



s = string.format("Your database is marked as version {0}, but this client
requires a schema version {1}" or later", dbVersion, dbRequiredVersion)



Armin
Author
30 Jun 2005 3:47 PM
Robin Tucker
Superb thankyou.

Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:uq5WGlYfFHA.3912@tk2msftngp13.phx.gbl...
> "Robin Tucker" <idontwanttobespammedanymore@reallyidont.com> schrieb
>>
>> Given the need to (possibly) alter the position of various elements
>> in a string due to localisation, is it possible to build a string
>> using a "printf" style function, such that the source string can
>> also contain the position of the elements to follow?  Eg. :
>>
>>    printf ( "Your database is marked as version %d, but this client
>> requires a schema version %d" or later", dbVersion,
>> dbRequiredVersion);
>>
>> where in another locale, we might rearrange this sentance to
>> something like:
>>
>>    printf ( "Your database is marked %d as the version, but this
>> client requires a %d schema version or later", dbVersion,
>> dbRequiredVersion);
>
>
>
> s = string.format("Your database is marked as version {0}, but this client
> requires a schema version {1}" or later", dbVersion, dbRequiredVersion)
>
>
>
> Armin