网站开发的就业方向,即时热榜,展会展厅设计公司,具有营销价值好的网站/*
* brief: 根据split_symbol分割字符串
* param: str为要分割的字符串#xff0c;split_symbol是分隔符
* return#xff1a;返回garray的指针数组#xff0c;如果返回非空需要自己处理释放
*/
GPtrArray_autoptr char_sz_spilt(pchar* str, pchar split_symbol)
{if (NUL…/*
* brief: 根据split_symbol分割字符串
* param: str为要分割的字符串split_symbol是分隔符
* return返回garray的指针数组如果返回非空需要自己处理释放
*/
GPtrArray_autoptr char_sz_spilt(pchar* str, pchar split_symbol)
{if (NULL str || NULL split_symbol){log_error(__FILE__, __LINE__, str: %p split_symbol: %p, str, split_symbol);return NULL;}log_info(__FILE__, __LINE__, str %s, str);char sz_dir[MAX_PATH] {0};strcpy_s(sz_dir, MAX_PATH, str);GPtrArray_autoptr garray_spilt g_ptr_array_new();char *token;token strtok(sz_dir, split_symbol);while (token ! NULL){char *sz_temp str_notify_str_dup(token);log_debug(__FILE__, __LINE__, sz_temp : %s,sz_temp);g_ptr_array_add(garray_spilt, (gpointer) sz_temp);token strtok(NULL, split_symbol);}return garray_spilt;
}
以上代码实现了字符串根据特殊字符分割并放入glib的数组GPtrArray_autoptr是指针数组里面。如果项目有引用其它的数据结构也可以替换这个数组。