2014年02月12日 星期三 09:03
String Utility Functions是GLib提供的一组操作C style string的API,是对C语言标准库的增强。编程示例如下:
#include <stdio.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char **argv) {
    gchar *s=g_strdup("laomeng");
    printf("s: %s\n",s);
    g_free(s);
    s=g_strndup("laomeng",3);
    printf("s: %s\n",s);
    g_free(s);
    s=g_strdup("laozhang,laoyang,laoli,laomeng");
    gchar **ss=g_strsplit(s,",",0);
    g_free(s);
    
    int i=0;
    while(ss[i] != NULL) {
        printf("%s\n",ss[i]);
        i++;
    }
    s=g_strjoinv("|",ss);
    printf("join result: %s\n",s);
    s=g_strreverse(s);
    printf("reverse result: %s\n",s);
    g_free(s);
    g_strfreev(ss);
    return 0;
}
参考资料:
https://developer.gnome.org/glib/2.39/glib-String-Utility-Functions.html
Zeuux © 2025
京ICP备05028076号