"printf" style string method?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin Tucker

    #1

    "printf" style string method?


    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, dbRequiredVersi on);

    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, dbRequiredVersi on);



    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.ToStr ing +
    ", but this client requires a schema version " + dbRequiredVersi on.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


  • Armin Zingler

    #2
    Re: "printf&qu ot; style string method?

    "Robin Tucker" <idontwanttobes pammedanymore@r eallyidont.com> schrieb[color=blue]
    >
    > 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,
    > dbRequiredVersi on);
    >
    > 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,
    > dbRequiredVersi on);[/color]



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



    Armin

    Comment

    • Robin Tucker

      #3
      Re: &quot;printf&qu ot; style string method?

      Superb thankyou.

      "Armin Zingler" <az.nospam@free net.de> wrote in message
      news:uq5WGlYfFH A.3912@tk2msftn gp13.phx.gbl...[color=blue]
      > "Robin Tucker" <idontwanttobes pammedanymore@r eallyidont.com> schrieb[color=green]
      >>
      >> 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,
      >> dbRequiredVersi on);
      >>
      >> 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,
      >> dbRequiredVersi on);[/color]
      >
      >
      >
      > s = string.format(" Your database is marked as version {0}, but this client
      > requires a schema version {1}" or later", dbVersion, dbRequiredVersi on)
      >
      >
      >
      > Armin[/color]


      Comment

      Working...