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. Strings

Strings

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++helptutorialquestion
4 Posts 4 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.
  • G Offline
    G Offline
    gremlin06
    wrote on last edited by
    #1

    For about a week now i have been reading and reading but still can not make any sense about strings in C++ .Net. Problem 1 is comparing strings, for example: String* Str1 = "HELLO"; if (Str1 == "HELLO") // Also Tried using Compareto { TextBox1 -> Text = "Same"; Else TextBox1 -> Text = "Not The Same""; } I have even put in breaks just to make sure that the strings are the same - which they are. Problem 2, does left, right, mid still exsist? Thanks, Dave

    G A G 3 Replies Last reply
    0
    • G gremlin06

      For about a week now i have been reading and reading but still can not make any sense about strings in C++ .Net. Problem 1 is comparing strings, for example: String* Str1 = "HELLO"; if (Str1 == "HELLO") // Also Tried using Compareto { TextBox1 -> Text = "Same"; Else TextBox1 -> Text = "Not The Same""; } I have even put in breaks just to make sure that the strings are the same - which they are. Problem 2, does left, right, mid still exsist? Thanks, Dave

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

      You are comparing two objects not strings! This will work: String* Str1 = S"Hello"; if (Str1->CompareTo(S"Hello") == 0) ... However, the following will seem to work but you are actually comparing the same object to itself: String* Str1 = S"Hello"; if (Str1 == S"Hello") ... Str1 is actually pointing to S"Hello". S"Hello" really a String object. S"Hello" actually means new String("Hello"); Thus S"Hello" or (Str1) does not equal the literal string "Hello" (without the S prefix). Also, use the String object's method "SubString", for Left, Right and Mid.

      1 Reply Last reply
      0
      • G gremlin06

        For about a week now i have been reading and reading but still can not make any sense about strings in C++ .Net. Problem 1 is comparing strings, for example: String* Str1 = "HELLO"; if (Str1 == "HELLO") // Also Tried using Compareto { TextBox1 -> Text = "Same"; Else TextBox1 -> Text = "Not The Same""; } I have even put in breaks just to make sure that the strings are the same - which they are. Problem 2, does left, right, mid still exsist? Thanks, Dave

        A Offline
        A Offline
        AnsGe
        wrote on last edited by
        #3

        Hai, You can comapre the Strings using the static Compare method in the String class ie String* str=S"HELLO"; if(String::Compare(str,"HELLO")==0) //ie Same { TextBox1 -> Text = "Same"; } else { TextBox1 -> Text = "Not The Same""; } SubString function done all the left, right and mid functionalities by Anish

        1 Reply Last reply
        0
        • G gremlin06

          For about a week now i have been reading and reading but still can not make any sense about strings in C++ .Net. Problem 1 is comparing strings, for example: String* Str1 = "HELLO"; if (Str1 == "HELLO") // Also Tried using Compareto { TextBox1 -> Text = "Same"; Else TextBox1 -> Text = "Not The Same""; } I have even put in breaks just to make sure that the strings are the same - which they are. Problem 2, does left, right, mid still exsist? Thanks, Dave

          G Offline
          G Offline
          Gammill
          wrote on last edited by
          #4

          One more little thought to add to the above: You can not change a String object. Replace only deletes the old and creates a new object. Once created the String is fixed. So -- if in a loop changing a sting; be careful of using String. WedgeSoft

          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