compare string
-
Hi all, would anyone happen to know the equivalent of comparing a string declared variable or character? Sort of like strstr or strcmp, i just cant find which one is used for C-like string. Thanx in advance!
-
Hi all, would anyone happen to know the equivalent of comparing a string declared variable or character? Sort of like strstr or strcmp, i just cant find which one is used for C-like string. Thanx in advance!
To compare what kind of strings (sorry, I'm not following :))? Mark
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
-
To compare what kind of strings (sorry, I'm not following :))? Mark
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
string somecode;
strstr and strcmp does not work for string unless its declared as a char I dont know what to search for because i've already tried Google and nothing came up that refers to what im looking for. -
string somecode;
strstr and strcmp does not work for string unless its declared as a char I dont know what to search for because i've already tried Google and nothing came up that refers to what im looking for.Stuff like this? strcmp(str.c_str(), str2.c_str()); wcscmp(str.c_str(), str2.c_str()); operator== ( <string> )[^] basic_string::compare[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
-
string somecode;
strstr and strcmp does not work for string unless its declared as a char I dont know what to search for because i've already tried Google and nothing came up that refers to what im looking for.You may try the following CString s1, s2; if ( s1.GetLength() != s2.GetLengtth() ) // Not equal else { for( int i = 0; i < s1.GetLength(); i++ ) { if ( (Byte) s1.GetAt(i) != (BYTE) s2.GetAt(i) ) break; } if ( i != s1.GetLength() ) // String Not equal. else // String equal. } Hope this will help u, if ur string length is small.
Regards, Ram
-
string somecode;
strstr and strcmp does not work for string unless its declared as a char I dont know what to search for because i've already tried Google and nothing came up that refers to what im looking for.Try using CString::Compare.
// example for CString::Compare CString s1( "abc" ); CString s2( "abd" ); ASSERT( s1.Compare( s2 ) == -1 ); // Compare with another CString. ASSERT( s1.Compare( "abe" ) == -1 ); // Compare with LPTSTR string.
Regards, Paresh.
-
string somecode;
strstr and strcmp does not work for string unless its declared as a char I dont know what to search for because i've already tried Google and nothing came up that refers to what im looking for."string" class has overloaded "==" operator. You can directly use the == operator. Eg: string s1("hi"); string s2("hello"); if (s1==s2) { .... } else { .... }
-
You may try the following CString s1, s2; if ( s1.GetLength() != s2.GetLengtth() ) // Not equal else { for( int i = 0; i < s1.GetLength(); i++ ) { if ( (Byte) s1.GetAt(i) != (BYTE) s2.GetAt(i) ) break; } if ( i != s1.GetLength() ) // String Not equal. else // String equal. } Hope this will help u, if ur string length is small.
Regards, Ram
Why do people continue to recommend using
CString
methods when the OP is using astring
object? It just doesn't make sense. :rolleyes: Furthermore, why would you not just useCString
'sCompare()
,CompareNoCase()
, or== operator
?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne