关于VC++的字符串操作

发布网友 发布时间:2022-04-24 06:33

我来回答

1个回答

热心网友 时间:2022-06-16 23:56

VC++当然也支持C语言中的那些库函数 以及C++中的String类的一些操作MFC封装的CString类的成员方法有下面这些:The String as an Array GetLengthReturns the number of characters in a CString object. For multibyte characters, counts each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two characters.IsEmptyTests whether a CString object contains no characters.EmptyForces a string to have 0 length.GetAtReturns the character at a given position.operator []Returns the character at a given position — operator substitution for GetAt.SetAtSets a character at a given position.operator LPCTSTR Directly accesses characters stored in a CString object as a C-style string.
Assignment/Concatenation operator =Assigns a new value to a CString object.operator +Concatenates two strings and returns a new string.operator +=Concatenates a new string to the end of an existing string.
Comparison operator == <, etc.Comparison operators (case sensitive).CompareCompares two strings (case sensitive).CompareNoCaseCompares two strings (case insensitive).CollateCompares two strings (case sensitive, uses locale-specific information).CollateNoCaseCompares two strings (case insensitive, uses locale-specific information).
Extraction MidExtracts the middle part of a string (like the Basic MID$ function).LeftExtracts the left part of a string (like the Basic LEFT$ function).RightExtracts the right part of a string (like the Basic RIGHT$ function).SpanIncludingExtracts a substring that contains only the characters in a set.SpanExcludingExtracts a substring that contains only the characters not in a set.
Other Conversions MakeUpperConverts all the characters in this string to uppercase characters.MakeLowerConverts all the characters in this string to lowercase characters.MakeReverseReverses the characters in this string.ReplaceReplaces indicated characters with other characters.RemoveRemoves indicated characters from a string.InsertInserts a single character or a substring at the given index within the string.DeleteDeletes a character or characters from a string.FormatFormat the string as sprintf does.FormatVFormats the string as vsprintf does.TrimLeftTrim leading whitespace characters from the string.TrimRightTrim trailing whitespace characters from the string.FormatMessageFormats a message string.
Searching FindFinds a character or substring inside a larger string.ReverseFindFinds a character inside a larger string; starts from the end.FindOneOfFinds the first matching character from a set.
Archive/Dump operator <<Inserts a CString object to an archive or mp context.operator >>Extracts a CString object from an archive.
Buffer Access GetBufferReturns a pointer to the characters in the CString.GetBufferSetLengthReturns a pointer to the characters in the CString, truncating to the specified length.ReleaseBufferReleases control of the buffer returned by GetBuffer.FreeExtraRemoves any overhead of this string object by freeing any extra memory previously allocated to the string.LockBufferDisables reference counting and protects the string in the buffer.UnlockBufferEnables reference counting and releases the string in the buffer.
Windows-Specific AllocSysStringAllocates a BSTR from CString data.SetSysStringSets an existing BSTR object with data from a CString object.LoadStringLoads an existing CString object from a Windows resource.AnsiToOemMakes an in-place conversion from the ANSI character set to the OEM character set.OemToAnsiMakes an in-place conversion from the OEM character set to the ANSI character set.

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com