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