Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. is there any function similar to sprintf in C++.Net?

is there any function similar to sprintf in C++.Net?

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++databasequestionworkspace
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kranti1251984
    wrote on last edited by
    #1

    Hi, I've to write a query which requires a function similar to "sprintf" in C For e.g. String *query; // in c++.net sprintf(query, "Select * from table_name where number = %d", no); // in C How can this be done in this environment? Thanks, Kranti

    2 1 Reply Last reply
    0
    • K Kranti1251984

      Hi, I've to write a query which requires a function similar to "sprintf" in C For e.g. String *query; // in c++.net sprintf(query, "Select * from table_name where number = %d", no); // in C How can this be done in this environment? Thanks, Kranti

      2 Offline
      2 Offline
      2bee
      wrote on last edited by
      #2

      Kranti1251984 wrote:

      I've to write a query which requires a function similar to "sprintf" in C For e.g. String *query; // in c++.net sprintf(query, "Select * from table_name where number = %d", no); // in C How can this be done in this environment?

      Hi Kranti1251984, yes, there is actually. For instance you could use: System::String::Format(...) String^ s = String::Format( "(C) Currency: . . . . . . . . {0:C}\n" + "(D) Decimal:. . . . . . . . . {0:D}\n" + "(E) Scientific: . . . . . . . {1:E}\n" + "(F) Fixed point:. . . . . . . {1:F}\n" + "(G) General:. . . . . . . . . {0:G}\n" + " (default):. . . . . . . . {0} (default = 'G')\n" + "(N) Number: . . . . . . . . . {0:N}\n" + "(P) Percent:. . . . . . . . . {1:P}\n" + "(R) Round-trip: . . . . . . . {1:R}\n" + "(X) Hexadecimal:. . . . . . . {0:X}\n", -123, -123.45f); Console::WriteLine(s); In addition i would like to point out, that it would be more secure to use parameters when constructing dynamic SQL statements. best regards Tobias

      G 1 Reply Last reply
      0
      • 2 2bee

        Kranti1251984 wrote:

        I've to write a query which requires a function similar to "sprintf" in C For e.g. String *query; // in c++.net sprintf(query, "Select * from table_name where number = %d", no); // in C How can this be done in this environment?

        Hi Kranti1251984, yes, there is actually. For instance you could use: System::String::Format(...) String^ s = String::Format( "(C) Currency: . . . . . . . . {0:C}\n" + "(D) Decimal:. . . . . . . . . {0:D}\n" + "(E) Scientific: . . . . . . . {1:E}\n" + "(F) Fixed point:. . . . . . . {1:F}\n" + "(G) General:. . . . . . . . . {0:G}\n" + " (default):. . . . . . . . {0} (default = 'G')\n" + "(N) Number: . . . . . . . . . {0:N}\n" + "(P) Percent:. . . . . . . . . {1:P}\n" + "(R) Round-trip: . . . . . . . {1:R}\n" + "(X) Hexadecimal:. . . . . . . {0:X}\n", -123, -123.45f); Console::WriteLine(s); In addition i would like to point out, that it would be more secure to use parameters when constructing dynamic SQL statements. best regards Tobias

        G Offline
        G Offline
        George L Jackson
        wrote on last edited by
        #3

        2beeIn addition i would like to point out, that it would be more secure to use parameters when constructing dynamic SQL statements.

        Just to add to Tobias' quoted comment, SQL Injection can be a big problem. For instance, a user can "inject" a DELETE statement into your programmically built SQL string and do some serious damage. Using parameters, SQL injection is impossible.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups