具有多个连续分隔符的strtok行为 [英] strtok behavior with multiple consecutive delimiters

查看:104
本文介绍了具有多个连续分隔符的strtok行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,无论白天在您的地方都很好..

请有人告诉我,strtok的标准行为是什么,

如遇到两个或更多连续的分隔符,如

(省略检查)


char tst [] =" this\\\\\\\\\\\\\\\\\\\ \ n \ nnline";

^^^^ ^^^^^^

char * tok = strtok(tst," \\\
" ;);

tok = strtok(NULL," \ n");

等等..


上面标记的''\ n''群体会一个一个地或整个

组一起消费吗?


非常感谢你/>

Hello, and good whatever daytime is at your place..
please can somebody tell me, what the standard behavior of strtok shall be,
if it encounters two or more consecutive delimiters like in
(checks omitted)

char tst[] = "this\nis\n\nan\nempty\n\n\nline";
^^^^ ^^^^^^
char *tok = strtok(tst, "\n");
tok = strtok(NULL, "\n");
and so on..

will the groups of ''\n'' marked above be consumed one by one or the whole
group together?

Thank you very much

推荐答案

Geometer写道:
Geometer wrote:
请有人告诉我,strtok的标准行为应该是什么? >是,如果它遇到两个或更多连续的分隔符,如
(检查省略)

char tst [] =" this \\ n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ n");
tok = strtok(NULL," \ n");
依旧..

将是''\ n 上面标记的是一个一个或整个
组合在一起?
please can somebody tell me, what the standard behavior of strtok shall
be, if it encounters two or more consecutive delimiters like in
(checks omitted)

char tst[] = "this\nis\n\nan\nempty\n\n\nline";
^^^^ ^^^^^^
char *tok = strtok(tst, "\n");
tok = strtok(NULL, "\n");
and so on..

will the groups of ''\n'' marked above be consumed one by one or the whole
group together?




是的。


但是为什么你不只是写一个测试用例并看到了?


继续前进,不要使用strtok()。谷歌可以替换,可能包括一个正则表达式系统的b $ b。然后你可以控制这些细节。


-

Phlip
http://c2.com/cgi/wiki?ZeekLand < - 不是博客!!!



Yes.

But why didn''t you just write a test case and see?

Going forward, don''t use strtok(). Google for a replacement, possibly
including a Regex system. Then you can control such details.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!

<

Geometer写道:
Geometer wrote:
您好,无论白天在哪里都很好..

请有人告诉我,strtok的标准行为是什么如果它遇到两个或多个连续的分隔符,如
(省略检查)

char tst [] =" this \\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > tok = strtok(NULL," \ n");
依旧..

将上面标记的''\ n''组逐个消费或整个
组合在一起?

非常感谢
Hello, and good whatever daytime is at your place..
please can somebody tell me, what the standard behavior of strtok shall be,
if it encounters two or more consecutive delimiters like in
(checks omitted)

char tst[] = "this\nis\n\nan\nempty\n\n\nline";
^^^^ ^^^^^^
char *tok = strtok(tst, "\n");
tok = strtok(NULL, "\n");
and so on..

will the groups of ''\n'' marked above be consumed one by one or the whole
group together?

Thank you very much




< quote src =&quo t; strok的man-page。">


切勿使用这些功能。如果你这样做,请注意:

这些函数修改它们的第一个参数。

这些函数不能用于常量字符串。

的身份分隔字符丢失。

strtok()函数在解析时使用静态缓冲区,

所以它不是线程安全的。


< / quote>


问候,


Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/





-

几何学

Dipl.Ing。 Erwin Lebloch


Hauptplatz 39

2130 Mistelbach - N?

电话:02572/4300
www.lebloch.at
ge ****** @ lebloch.at

" Phlip" < pH值****** @ yahoo.com> schrieb im Newsbeitrag

新闻:%d ******************* @ newssvr30.news.prodigy。 com ...


--
Geometer
Dipl.Ing. Erwin Lebloch

Hauptplatz 39
2130 Mistelbach - N?
Tel.: 02572/4300

www.lebloch.at
ge******@lebloch.at
"Phlip" <ph******@yahoo.com> schrieb im Newsbeitrag
news:%d*******************@newssvr30.news.prodigy. com...
Geometer写道:
Geometer wrote:
请有人告诉我,strtok的标准行为是什么,如果遇到两个或更多连续的分隔符,如
(省略检查)

char tst [] =" this \\\\\\\\\\\\\\\\\\\ nline" ;;
^^^^ ^^^^^^
char * tok = strtok(tst," \ n");
tok = strtok(NULL," \\ \\ n;
等等。

将上面标记的''\ n''群体一个一个地或整个
组一起消费?
please can somebody tell me, what the standard behavior of strtok shall
be, if it encounters two or more consecutive delimiters like in
(checks omitted)

char tst[] = "this\nis\n\nan\nempty\n\n\nline";
^^^^ ^^^^^^
char *tok = strtok(tst, "\n");
tok = strtok(NULL, "\n");
and so on..

will the groups of ''\n'' marked above be consumed one by one or the whole
group together?



是的。

但是你为什么不写一个测试用例并看看?



Yes.

But why didn''t you just write a test case and see?




我做了:)。我只是想知道这是否是

标准所要求的行为以及C和C ++之间是否存在差异。

感谢您的回复。


Robert



I did :). I just wanted to know if this is the behavior required by the
standard and whether there is a difference betwenn C and C++.
Thanks for your response.

Robert


这篇关于具有多个连续分隔符的strtok行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆