⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.manipulation.html

📁 PTypes (C++ Portable Types Library) is a simple alternative to the STL that includes multithreading
💻 HTML
字号:
<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><head><!-- #BeginEditable "doctitle" --> <title>PTypes: string: manipulation</title><!-- #EndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" href="styles.css"></head><body bgcolor="#FFFFFF" leftmargin="40" marginwidth="40"><p><a href="../index.html"><img src="title-1.7.gif" width="213" height="34" alt="C++ Portable Types Library (PTypes) Version 1.7" border="0"></a> <hr noshade><!-- #BeginEditable "body" --> <p class="hpath"><a href="index.html">Top</a>: <a href="basic.html">Basic types</a>: <a href="string.html">string</a>: Manipulation</p><blockquote> <pre class="lang">#include &lt;ptypes.h&gt;<span class="comment">// get/set length and misc.</span>int    length(const string& s);int    setlength(string&, int);char*  unique(string&);string dup(const string& s);void   clear(string& s);bool   isempty(const string& s);<span class="comment">// concatenate</span>void   concat(string& s, const char* sc, int catlen);<span class="comment">// copy (get substring by position and length)</span>string copy(const string& s, int from, int cnt);<span class="comment">// insert string or character</span>void   ins(const char* s1, string& s, int at);void   ins(char s1, string& s, int at);void   ins(const string& s1, string& s, int at);void   ins(const char* s1, int s1len, string& s, int at);<span class="comment">// delete substring</span>void   del(string& s, int at, int cnt);<span class="comment">// find substring or character</span>int    pos(const char* s1, const string& s);int    pos(char s1, const string& s);int    pos(const string& s1, const string& s);int    rpos(char s1, const string& s);<span class="comment">// compare substring</span>bool   contains(const char* s1, const string& s, int at);bool   contains(char s1, const string& s, int at);bool   contains(const string& s1, const string& s, int at);bool   contains(const char* s1, int s1len, const string& s, int at);<span class="comment">// conversion</span>string itobase(large value, int base, int width = 0, char pad = ' ');string itostring(<i>&lt;ordinal</i>&gt; v);large  stringtoi(const string&amp; s);string lowercase(const string&amp; s);</pre></blockquote><p><span class="def">int length(const string& s)</span> returns the actual length of the string, <b>not</b> counting the terminating null-symbol.</p><p><span class="def">setlength(string&, int)</span> changes the actual length of the string. The content of the original string is preserved, however the content of extra characters added during reallocation is undefined.</p><p><span class="def">char* unique(string&)</span> makes the string buffer unique, i.e. a new buffer is allocated and data is copied if necessary, so that the reference count after calling this function is guaranteed to be 1. All string manipulation functions call <span class="lang">unique()</span> whenever a modification is made on the string buffer. You may need to call this function explicitly to obtain a character pointer to the buffer; in all other cases reference counting mechanism works transparently.</p><p><span class="def">string dup(const string& s)</span> creates a unique copy of the string <span class="lang">s</span>.</p><p><span class="def">bool isempty(string&amp;)</span> returns true if the given string is empty. Using this function is preferable to comparing the string with empty string literal &quot;&quot;.</p><p><span class="def">clear(string&amp;)</span> makes the given string empty. Using this function is preferable to assigning an empty string literal &quot;&quot;.</p><p><span class="def">concat(string& s, const char* sc, int catlen)</span> adds the given buffer <span class="lang">sc</span> of length <span class="lang">catlen</span> to the string object <span class="lang">s</span>. Use operators + and += instead to concatenate characters, null-terminated strings and string objects.</p><p><span class="def">ins(..., string& s, int at)</span> inserts a character, a null-terminated string, a string object or a buffer with specified length into string object <span class="lang">s</span> at the given position <span class="lang">at</span>. If the position is out of bounds, <span class="lang">ins()</span> does nothing.</p><p><span class="def">del(string& s, int at, int cnt)</span> deletes <span class="lang">cnt</span> characters starting from position <span class="lang">at</span> of the string <span class="lang">s</span>.</p><p><span class="def">int pos(..., const string& s)</span> returns the position of the first occurrence of a character, a null-terminated string or a string object (first parameter) in the source string <span class="lang">s</span>, or returns -1 if the substring is not found. Function <span class="lang">rpos()</span> performs reverse-search.</p><p><span class="def">bool contains(..., const string& s, int at)</span> returns true if the given character, null-terminated string or string object (first parameter) equals the substring of <span class="lang">s</span> at the given position <span class="lang">at</span>.</p><p><span class="def">string itobase(large value, int base, int width = 0, char pad = ' ')</span> converts an integer value to a string with the numeration base specified by <span class="lang">base</span>, which can be in the range 2 - 64. Additionally, to right-justify the resulting string you can specify <span class="lang">width</span> and <span class="lang">pad</span> parameters.</p><p><span class="def">string itostring(<i>&lt;ordinal&gt;</i> v)</span> converts the given ordinal value <span class="lang">v</span> to a string. Various overloaded versions of this function accept ordinal values of different sizes.</p><p><span class="def">large stringtoi(const string&amp; s)</span> converts a string to a 64-bit integer. This function accepts only positive numbers and 0. It returns -1 if the string does not represent a valid positive number. <span class="lang">Stringtoi()</span> replaces <span class="lang">atoll()</span>, which is not present on some systems (e.g. on BSD clone and Darwin). Note an important difference between these two functions: on error <span class="lang">atoll()</span> returns 0, whereas PTypes' <span class="lang">stringtoi()</span> returns -1.</p><p><span class="def">string lowercase(const string&amp; s)</span> converts all characters of the given string <span class="lang">s</span> to lower case. The current version of the library &quot;understands&quot; only lower ASCII characters; all other characters remain unchanged.</p><p class="seealso">See also: <a href="string.constructors.html">Constructors/destructors</a>, <a href="string.operators.html">Operators</a>, <a href="string.typecasts.html">Typecasts</a></p><!-- #EndEditable --><hr size="1"><a href="../index.html" class="ns">PTypes home</a></body><!-- #EndTemplate --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -