📄 xstring.shtml
字号:
<HTML><!-- Header information--><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META NAME="Author" CONTENT="Guy Gascoigne - Piggford"> <TITLE>String - Extended Strings</TITLE></HEAD><!-- Set background properties --><body background="../fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed"><!-- A word from our sponsors... --><table WIDTH="100%"><tr WIDTH="100%"><td align=center><!--#exec cgi="/cgi/ads.cgi"--><td></tr></table><!-- Article Title --><CENTER><H3><FONT COLOR="#AOAO99">Extended Strings</FONT></H3></CENTER><CENTER><H3><HR></H3></CENTER><p>This article was contributed by <ahref="mailto:Joachim.Raidl@iname.com">Joachim Raidl</a>. </p><p>The <strong>XString</strong>-class is a powerfull extension tothe standard CString-class. Whereever you use a CString you cannow use a XString with much more functionality. The classincludes many string-functions I missed in CString, likeremoving, replacing or inserting strings into another,convertingfunctions to double or int and case-insensitive find,replace and remove. But the most powerfull extension is a methodI called 'Elementstrings'. Most of the functions are const andreturn a XString, so you can use them in an expression. Thefunctionality of this class is not very difficult to understandor to implement, but in my case, it saves a lot of time in myprojects.</p><p>If you miss some functions which could be usefull to extendthis class please contact me.</p><p><a href="#stringfkt">Additional String functions</a><br><a href="#elementstring">What are Elementstrings?</a><br><a href="#elemstringfkt">Elementstring functions</a><br><a href="#friends">Friend functions</a></p><table border="0" width="100%"> <tr> <td align="center" width="30%"><a href="xstring_source.zip">Download source file (8 KB)</a></td> <td align="right" colspan="2" width="30%">(comments in german)</td> </tr></table><h4><a name="stringfkt"></a>Additional Stringfunctions:</h4><table border="1" cellspacing="1"> <tr> <td bgcolor="#C0C0C0"><font color="#000000"><strong>Function</strong></font></td> <td bgcolor="#C0C0C0"><font color="#000000"><strong>Description</strong></font></td> <td bgcolor="#C0C0C0"><font color="#000000"><strong>Example</strong></font></td> <td bgcolor="#C0C0C0"><font color="#000000"><strong>Result</strong></font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString num("12.345");</em></font></td> </tr> <tr> <td><strong>Double</strong></td> <td>Convertion to double</td> <td><font color="#990000">num.Double()</font></td> <td><font color="#000000">12.345</font></td> </tr> <tr> <td><strong>Int</strong></td> <td>Convertion to int</td> <td><font color="#990000">num.Int()</font></td> <td><font color="#000000">12</font></td> </tr> <tr> <td><strong>Char</strong></td> <td>Convertion to char</td> <td><font color="#990000">num.Char()</font></td> <td><font color="#000000">1</font></td> </tr> <tr> <td><strong>Bool</strong></td> <td>Convertion to bool</td> <td><font color="#990000">num.Bool()</font></td> <td><font color="#000000">true</font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString test("Test Test");</em></font></td> </tr> <tr> <td><strong>Remove</strong></td> <td>Remove first occurence of a string, char or range</td> <td><font color="#990000">test.Remove('e')</font></td> <td><font color="#000000">"Tst Test"</font></td> </tr> <tr> <td><strong>RemoveAll</strong></td> <td>Remove all occurences of a string or char</td> <td><font color="#990000">test.RemoveAll("e")</font></td> <td><font color="#000000">"Tst Tst"</font></td> </tr> <tr> <td><strong>Replace</strong></td> <td>Replace first occurence of a string, char or range with another string</td> <td><font color="#990000">test.Replace("x", "e")</font></td> <td><font color="#000000">"Txst Test"</font></td> </tr> <tr> <td><strong>ReplaceAll</strong></td> <td>Replace all occurences of a string or char with another string</td> <td><font color="#990000">test.ReplaceAll("x", "e")</font></td> <td><font color="#000000">"Txst Txst"</font></td> </tr> <tr> <td><strong>Insert</strong></td> <td>Inserts a string at a given position</td> <td><font color="#990000">test.Insert("e", 1)</font></td> <td><font color="#000000">"Teest Test"</font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString op("Test");<br> XString leer;</em></font></td> </tr> <tr> <td><strong>operator--</strong></td> <td>Remove last character of the string</td> <td><font color="#990000">op--, --op</font></td> <td><font color="#000000">"Tes"</font></td> </tr> <tr> <td><strong>operator!</strong></td> <td>Indicates, wheter the string was empty</td> <td><font color="#990000">!op<br> !lee</font></td> <td><font color="#000000">false<br> true</font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString test("Test");</em></font></td> </tr> <tr> <td><strong>NCFind<br> NCRemove<br> NCReplace</strong></td> <td>Like Find, Remove or Replace, but case-insensitiv (<strong>N</strong>o <strong>C</strong>ase)</td> <td><font color="#990000">test.Find("E")<br> test.NCFind("E")</font></td> <td><font color="#000000">-1<br> 1</font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString test(" Test ");</em></font></td> </tr> <tr> <td><strong>Reverse</strong></td> <td>Reverses the string</td> <td><font color="#990000">test.Reverse()</font></td> <td><font color="#000000">" tseT "</font></td> </tr> <tr> <td><strong>Trim</strong></td> <td>Delete leading and trailing whitespaces</td> <td><font color="#990000">test..Trim()</font></td> <td><font color="#000000">"Test"</font></td> </tr> <tr> <td><strong>Lower</strong></td> <td>Returns lowercase string</td> <td><font color="#990000">test.Lower()</font></td> <td><font color="#000000">" test "</font></td> </tr> <tr> <td><strong>Upper</strong></td> <td>Returns uppercase string</td> <td><font color="#990000">test.Upper()</font></td> <td><font color="#000000">" TEST "</font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString test("Test Test");</em></font></td> </tr> <tr> <td><strong>FromTo</strong></td> <td>Like Mid, but using positions</td> <td><font color="#990000">test.FromTo(5, 7)</font></td> <td><font color="#000000">"Tes"</font></td> </tr> <tr> <td><strong>Count</strong></td> <td>Counts the occurence of a string or char in another string</td> <td><font color="#990000">test.Count('e')</font></td> <td><font color="#000000">2</font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString test("Test")</em></font></td> </tr> <tr> <td><strong>FindIndex</strong></td> <td>Search the position of the first occurence of a char</td> <td><font color="#990000">test.FindIndex('s')</font></td> <td><font color="#000000">2</font></td> </tr> <tr> <td><strong>Fill</strong></td> <td>Fill the string to the specified length with trailing spaces</td> <td><font color="#990000">test.Fill(5)</font></td> <td><font color="#000000">"Test "</font></td> </tr> <tr> <td> </td> <td> </td> <td colspan="2"><font color="#990000"><em>XString error("Error * in Line *");</em></font></td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -