![]() ![]() Use Collate only where you must abide by the sorting rules as specified by the current locale. The Collate method of CString is locale-sensitive and is often slower than Compare. Compare, operator=, and CompareNoCase are MBCS and Unicode aware CompareNoCase is also case-insensitive. ![]() The Compare method and the = operator for CString are equivalent. Message contains "This is a big test".Īt least one argument to the concatenation operators (+ or +=) must be a CString object, but you can use a constant character string (for example, "big") or a char (for example, 'x') for the other argument. CString s1 = _T("This ") // Cascading concatenation To concatenate two CString objects, use the concatenation operators (+ or +=), as follows. (This resembles accessing array elements by index, as in standard C-style strings.) Index values for CString characters are zero-based. ![]() You can also use the array element, or subscript, operator ( ) instead of GetAt to get individual characters. You can access individual characters in a CString object by using the GetAt and SetAt methods. For more information, see Unicode and Multibyte Character Set (MBCS) Support.Īccessing Individual Characters in a CString To write your application so that it can be compiled for Unicode or for ANSI, code literal strings by using the _T macro. For more information about how to use CString objects as values, see CString Semantics. Therefore, the two strings do not share a reference to the actual characters that make up the string. The contents of a CString object are copied when one CString object is assigned to another. CString oldString = _T("This is a test") CString myString = _T("This is a test") Īssign the value of one CString to another CString object. You can assign C-style literal strings to a CString just as you can assign one CString object to another.Īssign the value of a C literal string to a CString object. Creating CString Objects from Standard C Literal Strings For a string class that is for use in a C++/CLI managed project, use System.String. Some of the methods duplicate and, in some cases, surpass the string services of the C run-time libraries. CStringT is defined in cstringt.h.ĬString, CStringA, and CStringW each get a set of the methods and operators defined by CStringT for use with the string data they support. Similarly defined classes are CStringA and CStringW.ĬString, CStringA, and CStringW are defined in atlstr.h. More exactly, CString is a typedef of an explicit specialization of CStringT, which is a common way to use a class template to define a class. This topic explains the following basic CString operations:Ĭreating CString objects from standard C literal stringsĪccessing individual characters in a CStringĬlass CString is based on class template CStringT Class. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |