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

📄 glib-string-utility-functions.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
                                                         <a class="link" href="glib-Basic-Types.html#gint">gint</a> max_tokens);void                <a class="link" href="glib-String-Utility-Functions.html#g-strfreev">g_strfreev</a>                          (<a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **str_array);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*              <a class="link" href="glib-String-Utility-Functions.html#g-strconcat">g_strconcat</a>                         (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *string1,                                                         ...);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*              <a class="link" href="glib-String-Utility-Functions.html#g-strjoin">g_strjoin</a>                           (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *separator,                                                         ...);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*              <a class="link" href="glib-String-Utility-Functions.html#g-strjoinv">g_strjoinv</a>                          (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *separator,                                                         <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **str_array);<a class="link" href="glib-Basic-Types.html#guint">guint</a>               <a class="link" href="glib-String-Utility-Functions.html#g-strv-length">g_strv_length</a>                       (<a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **str_array);const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*        <a class="link" href="glib-String-Utility-Functions.html#g-strerror">g_strerror</a>                          (<a class="link" href="glib-Basic-Types.html#gint">gint</a> errnum);const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*        <a class="link" href="glib-String-Utility-Functions.html#g-strsignal">g_strsignal</a>                         (<a class="link" href="glib-Basic-Types.html#gint">gint</a> signum);</pre></div><div class="refsect1" lang="en"><a name="id2964631"></a><h2>Description</h2><p>This section describes a number of utility functions for creating,duplicating, and manipulating strings.</p><p>Note that the functions <a class="link" href="glib-String-Utility-Functions.html#g-printf"><code class="function">g_printf()</code></a>, <a class="link" href="glib-String-Utility-Functions.html#g-fprintf"><code class="function">g_fprintf()</code></a>, <a class="link" href="glib-String-Utility-Functions.html#g-sprintf"><code class="function">g_sprintf()</code></a>, <a class="link" href="glib-String-Utility-Functions.html#g-snprintf"><code class="function">g_snprintf()</code></a>,<a class="link" href="glib-String-Utility-Functions.html#g-vprintf"><code class="function">g_vprintf()</code></a>, <a class="link" href="glib-String-Utility-Functions.html#g-vfprintf"><code class="function">g_vfprintf()</code></a>, <a class="link" href="glib-String-Utility-Functions.html#g-vsprintf"><code class="function">g_vsprintf()</code></a> and <a class="link" href="glib-String-Utility-Functions.html#g-vsnprintf"><code class="function">g_vsnprintf()</code></a> are declared in the header <code class="filename">gprintf.h</code> which is <span class="emphasis"><em>not</em></span>included in <code class="filename">glib.h</code> (otherwise using <code class="filename">glib.h</code> would drag in <code class="filename">stdio.h</code>), soyou'll have to explicitly include <code class="literal">&lt;glib/gprintf.h&gt;</code> in order to use the GLib <code class="function">printf()</code> functions. </p><p><a name="string-precision"></a>While you may use the <code class="function">printf()</code> functions to format UTF-8 strings, notice thatthe precision of a <code class="literal">%Ns</code> parameter is interpreted as thenumber of <span class="emphasis"><em>bytes</em></span>, not <span class="emphasis"><em>characters</em></span> to print.On top of that, the GNU libc implementation of the <code class="function">printf()</code> functions has the "feature"that it checks that the string given for the <code class="literal">%Ns</code> parameterconsists of a whole number of characters in the current encoding. So, unless youare sure you are always going to be in an UTF-8 locale or your know your text is restricted to ASCII, avoid using <code class="literal">%Ns</code>.If your intention is to format strings for a certain number of columns, then <code class="literal">%Ns</code> is not a correct solution anyway, since it fails to take wide characters (see <a class="link" href="glib-Unicode-Manipulation.html#g-unichar-iswide"><code class="function">g_unichar_iswide()</code></a>) into account.</p></div><div class="refsect1" lang="en"><a name="id2964860"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2964870"></a><h3><a name="g-strdup"></a>g_strdup ()</h3><a class="indexterm" name="id2964882"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*              g_strdup                            (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *str);</pre><p>Duplicates a string.If <em class="parameter"><code>str</code></em> is <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> it returns <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.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><p><span class="term"><em class="parameter"><code>str</code></em>&#160;:</span></p></td><td>the string to duplicate.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td>a newly-allocated copy of <em class="parameter"><code>str</code></em>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2964973"></a><h3><a name="g-strndup"></a>g_strndup ()</h3><a class="indexterm" name="id2964986"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*              g_strndup                           (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *str,                                                         <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> n);</pre><p>Duplicates the first <em class="parameter"><code>n</code></em> bytes of a string, returning a newly-allocatedbuffer <em class="parameter"><code>n</code></em> + 1 bytes 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> bytes long the buffer is padded with nuls.If <em class="parameter"><code>str</code></em> is <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> it returns <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.The returned value should be freed when no longer needed.</p><p></p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>To copy a number of characters from a UTF-8 encoded string, use<a class="link" href="glib-Unicode-Manipulation.html#g-utf8-strncpy"><code class="function">g_utf8_strncpy()</code></a> instead.</p></div><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>str</code></em>&#160;:</span></p></td><td> the string to duplicate</td></tr><tr><td><p><span class="term"><em class="parameter"><code>n</code></em>&#160;:</span></p></td><td> the maximum number of bytes to copy from <em class="parameter"><code>str</code></em></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> a newly-allocated buffer containing the first <em class="parameter"><code>n</code></em> bytes          of <em class="parameter"><code>str</code></em>, nul-terminated </td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2965159"></a><h3><a name="g-strdupv"></a>g_strdupv ()</h3><a class="indexterm" name="id2965171"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>**             g_strdupv                           (<a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **str_array);</pre><p>Copies <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-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 class="link" href="glib-String-Utility-Functions.html#g-strfreev"><code class="function">g_strfreev()</code></a> does this for you. If calledon a <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> value, <a class="link" href="glib-String-Utility-Functions.html#g-strdupv"><code class="function">g_strdupv()</code></a> simply returns <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>str_array</code></em>&#160;:</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated array of strings.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> a new <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated array of strings.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2965307"></a><h3><a name="g-strnfill"></a>g_strnfill ()</h3><a class="indexterm" name="id2965319"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*              g_strnfill                          (<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> length,                                                         <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> fill_char);</pre><p>Creates a new string <em class="parameter"><code>length</code></em> bytes long filled with <em class="parameter"><code>fill_char</code></em>.The returned string should be freed when no longer needed.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>length</code></em>&#160;:</span></p></td><td> the length of the new string</td></tr><tr><td><p><span class="term"><em class="parameter"><code>fill_char</code></em>&#160;:</span></p></td><td> the byte to fill the string with</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></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="id2965422"></a><h3><a name="g-stpcpy"></a>g_stpcpy ()</h3><a class="indexterm" name="id2965434"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>*              g_stpcpy                            (<a class="link" 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><p><span class="term"><em class="parameter"><code>dest</code></em>&#160;:</span></p></td><td> destination buffer.</td></tr><tr>

⌨️ 快捷键说明

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