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. C++/CLI string formatting

C++/CLI string formatting

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++help
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.
  • J Offline
    J Offline
    J_E_D_I
    wrote on last edited by
    #1

    int MyInt;
    String^ MyString = MyInt.ToString();

    Guys, I need some help on C++/CLI please. Given an Int ("MyInt") how can I generate a string called "MyString" which is made up of only the first let's say 5 digits of the Int? I guess there must be a simple attribute that I can specify in the line above but I cannot find the right sintax. Any help would be appreciated. Many thanks.

    L 1 Reply Last reply
    0
    • J J_E_D_I

      int MyInt;
      String^ MyString = MyInt.ToString();

      Guys, I need some help on C++/CLI please. Given an Int ("MyInt") how can I generate a string called "MyString" which is made up of only the first let's say 5 digits of the Int? I guess there must be a simple attribute that I can specify in the line above but I cannot find the right sintax. Any help would be appreciated. Many thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, no there is no optional parameter that lets you specify that you only are interested in the N leftmost or N rightmost digits; ToString() will give all of them, you can throw away the part you do not want using string::SubString(). Not sure it makes much sense to do so. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      M 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, no there is no optional parameter that lets you specify that you only are interested in the N leftmost or N rightmost digits; ToString() will give all of them, you can throw away the part you do not want using string::SubString(). Not sure it makes much sense to do so. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        One could go totally overkill and implement an IFormatProvider/ICustomFormatter that automatically trims the string (using Convert.ToString(Intxx, IFormatProvider)). :laugh:

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        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