glib-string-utility-functions.html

来自「glid编写实例」· HTML 代码 · 共 1,304 行 · 第 1/5 页

HTML
1,304
字号
</table></div></div><hr><div class="refsect2" lang="en"><a name="id2939048"></a><h3><a name="g-strndup"></a>g_strndup ()</h3><a class="indexterm" name="id2939058"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_strndup                       (const <a href="glib-Basic-Types.html#gchar">gchar</a> *str,                                             <a href="glib-Basic-Types.html#gsize">gsize</a> n);</pre><p>Duplicates the first <em class="parameter"><code>n</code></em> characters of a string, returning a newly-allocatedbuffer <em class="parameter"><code>n</code></em> + 1 characters long which will always be nul-terminated.If <em class="parameter"><code>str</code></em> is less than <em class="parameter"><code>n</code></em> characters long the buffer is padded with nuls.If <em class="parameter"><code>str</code></em> is <code class="literal">NULL</code> it returns <code class="literal">NULL</code>.The returned value should be freed when no longer needed.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>str</code></em>&#160;:</span></td><td>the string to duplicate part of.</td></tr><tr><td><span class="term"><em class="parameter"><code>n</code></em>&#160;:</span></td><td>the maximum number of characters to copy from <em class="parameter"><code>str</code></em>.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>a newly-allocated buffer containing the first <em class="parameter"><code>n</code></em> characters of <em class="parameter"><code>str</code></em>,nul-terminated.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2939200"></a><h3><a name="g-strdupv"></a>g_strdupv ()</h3><a class="indexterm" name="id2939210"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>**     g_strdupv                       (<a href="glib-Basic-Types.html#gchar">gchar</a> **str_array);</pre><p>Copies <code class="literal">NULL</code>-terminated array of strings. The copy is a deep copy;the new array should be freed by first freeing each string, thenthe array itself. <a href="glib-String-Utility-Functions.html#g-strfreev"><code class="function">g_strfreev()</code></a> does this for you. If calledon a <code class="literal">NULL</code> value, <a href="glib-String-Utility-Functions.html#g-strdupv"><code class="function">g_strdupv()</code></a> simply returns <code class="literal">NULL</code>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>str_array</code></em>&#160;:</span></td><td> <code class="literal">NULL</code>-terminated array of strings.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> a new <code class="literal">NULL</code>-terminated array of strings.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2939324"></a><h3><a name="g-strnfill"></a>g_strnfill ()</h3><a class="indexterm" name="id2939334"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_strnfill                      (<a href="glib-Basic-Types.html#gsize">gsize</a> length,                                             <a href="glib-Basic-Types.html#gchar">gchar</a> fill_char);</pre><p>Creates a new string <em class="parameter"><code>length</code></em> characters long filled with <em class="parameter"><code>fill_char</code></em>.The returned string should be freed when no longer needed.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>length</code></em>&#160;:</span></td><td>the length of the new string.</td></tr><tr><td><span class="term"><em class="parameter"><code>fill_char</code></em>&#160;:</span></td><td>the character to fill the string with.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>a newly-allocated string filled the <em class="parameter"><code>fill_char</code></em>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2939433"></a><h3><a name="g-stpcpy"></a>g_stpcpy ()</h3><a class="indexterm" name="id2939443"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_stpcpy                        (<a href="glib-Basic-Types.html#gchar">gchar</a> *dest,                                             const char *src);</pre><p>Copies a nul-terminated string into the dest buffer, include thetrailing nul, and return a pointer to the trailing nul byte.This is useful for concatenating multiple strings togetherwithout having to repeatedly scan for the end.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>dest</code></em>&#160;:</span></td><td> destination buffer.</td></tr><tr><td><span class="term"><em class="parameter"><code>src</code></em>&#160;:</span></td><td> source string.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> a pointer to trailing nul byte.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2939529"></a><h3><a name="g-strstr-len"></a>g_strstr_len ()</h3><a class="indexterm" name="id2939539"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_strstr_len                    (const <a href="glib-Basic-Types.html#gchar">gchar</a> *haystack,                                             <a href="glib-Basic-Types.html#gssize">gssize</a> haystack_len,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *needle);</pre><p>Searches the string <em class="parameter"><code>haystack</code></em> for the first occurrenceof the string <em class="parameter"><code>needle</code></em>, limiting the length of the searchto <em class="parameter"><code>haystack_len</code></em>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>haystack</code></em>&#160;:</span></td><td> a string.</td></tr><tr><td><span class="term"><em class="parameter"><code>haystack_len</code></em>&#160;:</span></td><td> the maximum length of <em class="parameter"><code>haystack</code></em>.</td></tr><tr><td><span class="term"><em class="parameter"><code>needle</code></em>&#160;:</span></td><td> the string to search for.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> a pointer to the found occurrence, or   <code class="literal">NULL</code> if not found.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2939675"></a><h3><a name="g-strrstr"></a>g_strrstr ()</h3><a class="indexterm" name="id2939685"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_strrstr                       (const <a href="glib-Basic-Types.html#gchar">gchar</a> *haystack,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *needle);</pre><p>Searches the string <em class="parameter"><code>haystack</code></em> for the last occurrenceof the string <em class="parameter"><code>needle</code></em>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>haystack</code></em>&#160;:</span></td><td> a nul-terminated string.</td></tr><tr><td><span class="term"><em class="parameter"><code>needle</code></em>&#160;:</span></td><td> the nul-terminated string to search for.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> a pointer to the found occurrence, or   <code class="literal">NULL</code> if not found.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2939787"></a><h3><a name="g-strrstr-len"></a>g_strrstr_len ()</h3><a class="indexterm" name="id2939797"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>*      g_strrstr_len                   (const <a href="glib-Basic-Types.html#gchar">gchar</a> *haystack,                                             <a href="glib-Basic-Types.html#gssize">gssize</a> haystack_len,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *needle);</pre><p>Searches the string <em class="parameter"><code>haystack</code></em> for the last occurrenceof the string <em class="parameter"><code>needle</code></em>, limiting the length of the searchto <em class="parameter"><code>haystack_len</code></em>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>haystack</code></em>&#160;:</span></td><td> a nul-terminated string.</td></tr><tr><td><span class="term"><em class="parameter"><code>haystack_len</code></em>&#160;:</span></td><td> the maximum length of <em class="parameter"><code>haystack</code></em>.</td></tr><tr><td><span class="term"><em class="parameter"><code>needle</code></em>&#160;:</span></td><td> the nul-terminated string to search for.

⌨️ 快捷键说明

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