📄 cstring_ext.shtml.htm
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Zafir Anjum">
<TITLE>String - CString Extension</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><td>
</tr>
</table>
<CENTER>
<H3>
<FONT COLOR="#AOAO99">CString Extension</FONT></H3></CENTER>
<CENTER>
<H3>
<HR></H3></CENTER>
<p>There are innumerable MFC functions that need a CString object as an argument or return a CString object. Often, even if a function needs a char pointer, we still use a CString to hold the string. Although, the CString class has lots of features, it does lack a few very useful string manipulation functions. A case insensitive search funciton is one, a search and replace function is another. Fortunately, implementing these functionality is not very difficult. The CStringEx class given below derives from CString and adds a few useful functions. The CStringEx class does not add any member variables of its own, so that it can be freely interchanged with a CString object.
<p>The constructors in the CStringEx class parallel the constructor in CString and in fact simply chains into the corresponding CString constructor. Some of the CStringEx functions use knowledge of the internal structure of the CString object so there is a small chance that these functions might break if the CString implementation changes.
<p>The functions provided by CStringEx are quite easy to use and fairly simple to understand. The Insert() functions inserts a character or a sub-string within a string. The result is similar to inserting text in an edit control, the string is expanded to accommodate the sub-string. The Delete() function removes a segment from the string and shortens it. The Replace() function removes a sub-string and replaces it with another. Again, the string size is adjusted depending on the size of the sub-string that was removed and the size of the sub-string that was inserted.
<p>The find family of functions, finds a sub-string in the forward or the reverse direction. The NoCase version of these functions are case insensitive. The FindReplace() and FindReplaceNoCase() functions searches for a sub-string and replaces the matching sub-string with another string. The GetField() and GetDelimitedField() functions find a token in the string. The table below exemplifies the uses of these functions.
<p>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH="100%">
<TR><TD WIDTH="22%" VALIGN="TOP" BGCOLOR="#a0a0a0">
<FONT SIZE=2><P>String</FONT></TD>
<TD WIDTH="45%" VALIGN="TOP" BGCOLOR="#a0a0a0">
<FONT SIZE=2><P>Function</FONT></TD>
<TD WIDTH="33%" VALIGN="TOP" BGCOLOR="#a0a0a0">
<FONT SIZE=2><P>Result</FONT></TD>
</TR>
<TR><TD WIDTH="22%" VALIGN="TOP">
<FONT SIZE=2><P>xyz</FONT></TD>
<TD WIDTH="45%" VALIGN="TOP">
<FONT SIZE=2><P>Insert(1, 慳
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -