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. HELP: Fixed Length String ?

HELP: Fixed Length String ?

Scheduled Pinned Locked Moved Managed C++/CLI
helptutorialquestion
3 Posts 2 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.
  • F Offline
    F Offline
    Fritzables
    wrote on last edited by
    #1

    Hi all, I have a situation where I need to return a fixed length string regardless of the length of a string that has been assigned to it. For example, if I wanted to have String1 which is made up of 12 spaces, then assing a returned value to a String2 which can be anything from 1 to 12 characters in length, how is this best done ? The following may give you an idea where I'm coming from: String^ Result; //This needs to be a fixed 12 characters. String^ s1 = "ABC"; Result = s1; So I need Result to return 'ABC' + 9 spaces. Hope this all makes some sense.... Fritzables.

    G 1 Reply Last reply
    0
    • F Fritzables

      Hi all, I have a situation where I need to return a fixed length string regardless of the length of a string that has been assigned to it. For example, if I wanted to have String1 which is made up of 12 spaces, then assing a returned value to a String2 which can be anything from 1 to 12 characters in length, how is this best done ? The following may give you an idea where I'm coming from: String^ Result; //This needs to be a fixed 12 characters. String^ s1 = "ABC"; Result = s1; So I need Result to return 'ABC' + 9 spaces. Hope this all makes some sense.... Fritzables.

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

      String^ result; String^ s1 = "ABC"; result = (s1->Length > 12 ? s1->Substring(0, 12) : s1)->PadRight(12); Console::WriteLine("[{0}] Length={1}", result, result->Length); "We make a living by what we get, we make a life by what we give." --Winston Churchill

      F 1 Reply Last reply
      0
      • G George L Jackson

        String^ result; String^ s1 = "ABC"; result = (s1->Length > 12 ? s1->Substring(0, 12) : s1)->PadRight(12); Console::WriteLine("[{0}] Length={1}", result, result->Length); "We make a living by what we get, we make a life by what we give." --Winston Churchill

        F Offline
        F Offline
        Fritzables
        wrote on last edited by
        #3

        George, you're a legend.... works a treat. Thanks a million. Regards Pete

        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