Question

I am trying to compare 2 strings but getting weird results. On some computers, the comparison works correctly and on others, it does not. The codes is written in Visual Studio 2010 using managed C++.I have checked the strings and they look identical. Any thoughts?

String^ str1 = "string1";
char[] chars = "string1";
String^ str2 = new String(chars);
if(String::Compare(str1,str2)==0)
    return true;
else
    return false;
Was it helpful?

Solution

It turns out the issue was with the char* conversion to a string. The char* array was not properly null terminated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top