C++如何去除中文字符数组中的空格,或者将其根据空格分隔为几个。

sailing14 2012-07-30 08:00:27
普通的根据'\o'分割的 会有乱码 。
例如 :“北京 ay001.jpg”
分割为“北京”“ay001.jpg”

另外有个问题 中文字符串在字符数组中是怎么存储的。
...全文
223 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gloveing 2012-07-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
引用 1 楼 的回复:
strtok函数, 例:

C/C++ code

// crt_strtok.c
// compile with: /W3
// In this program, a loop uses strtok
// to print all the tokens (separated by commas
// or blanks) in the string n……
[/Quote]
参考:unicode编码
sailing14 2012-07-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
strtok函数, 例:

C/C++ code

// crt_strtok.c
// compile with: /W3
// In this program, a loop uses strtok
// to print all the tokens (separated by commas
// or blanks) in the string named "string"……
[/Quote]

谢谢。再问下。
中文字符串在字符数组中是怎么存储的。
wfq0987 2012-07-30
  • 打赏
  • 举报
回复
strtok函数, 例:

// crt_strtok.c
// compile with: /W3
// In this program, a loop uses strtok
// to print all the tokens (separated by commas
// or blanks) in the string named "string".
//
#include <string.h>
#include <stdio.h>

char string[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
char *token;

int main( void )
{
printf( "Tokens:\n" );

// Establish string and get the first token:
token = strtok( string, seps ); // C4996
// Note: strtok is deprecated; consider using strtok_s instead
while( token != NULL )
{
// While there are tokens in "string"
printf( " %s\n", token );

// Get next token:
token = strtok( NULL, seps ); // C4996
}
}

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧