子字符串 [英] Sub strings

查看:80
本文介绍了子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个包含Hello World的字符串,我如何将

''World''部分提取到另一个字符串中?在C中是否有子字符串功能?

提前感谢...


Polo

If I have a string which holds ''Hello World'', how would I extract the
''World'' part into another string? Is there a sub string function in C?

Thanks in advance...

Polo

推荐答案

2006-03-18,Polomint< po ******** @ hotmail2.com>写道:
On 2006-03-18, Polomint <po********@hotmail2.com> wrote:
如果我有一个字符串,其中包含''Hello World'',我如何将
''World''部分提取到另一个字符串中? C中是否有子字符串函数?
If I have a string which holds ''Hello World'', how would I extract the
''World'' part into another string? Is there a sub string function in C?




不是这样的。在这个_particular_的情况下,strchr(str,''W'')会给你你想要的
,但这显然不是一般的解决方案。


< ot>

我写了一个与posix正则表达式API很好地交互的函数来做

替换或复制子串。

< / ot>



Not as such. In this _particular_ case, strchr(str,''W'') will get you
what you want, but that''s obviously not a general solution.

<ot>
I wrote a function that interacts well with the posix regex API to do
substitutions or copy substrings.
</ot>


Polomint认为:
Polomint opined:
如果我有一个字符串,其中包含''Hello World'',我会将世界部分提取到另一个字符串中吗?在C中是否有子字符串函数?
If I have a string which holds ''Hello World'', how would I
extract the ''World'' part into another string? Is there a sub
string function in C?




查找函数`strstr()`。它在< string.h>中定义。这里是

a的简要说明,直接来自标准(我手写的是

手):


7.21.5.7 strstr函数


概要

#include< string.h>

char * strstr(const char * s1,const char * s2);


描述

strstr函数定位字符串中第一个出现的位置

指向的s1 s2指向的字符串中的字符序列(不包括

终止空字符)。


返回

strstr函数如果找不到该字符串,则返回指向所定位字符串的指针,

或空指针。如果s2指向

a字符串且长度为零,则该函数返回s1。


-

BR,Vladimir


我独自回来摇尾巴。



Look for function `strstr()`. It''s defined in <string.h>. Here''s
a brief description, straight from the Standard (I had it at
hand):

7.21.5.7 The strstr function

Synopsis
#include <string.h>
char *strstr(const char *s1, const char *s2);

Description
The strstr function locates the first occurrence in the string
pointed to by s1 of the sequence of characters (excluding the
terminating null character) in the string pointed to by s2.

Returns
The strstr function returns a pointer to the located string,
or a null pointer if the string is not found. If s2 points to
a string with zero length, the function returns s1.

--
BR, Vladimir

And I alone am returned to wag the tail.


Vladimir S. Oka认为:
Vladimir S. Oka opined:
Polomint认为:
Polomint opined:
如果我有一个包含Hello World的字符串,我将如何提取世界部分到另一个字符串? C中是否有子字符串函数?
If I have a string which holds ''Hello World'', how would I
extract the ''World'' part into another string? Is there a sub
string function in C?



查找函数`strstr()`。它在< string.h>中定义。这里有一个简短的描述,直接来自标准(我手边有):



Look for function `strstr()`. It''s defined in <string.h>. Here''s
a brief description, straight from the Standard (I had it at
hand):




忘了说:它赢了不要为你剪断字符串,但是会给你子字符串的下落。

。然后提取它应该很简单。


-

BR,Vladimir


如果上帝住在地球,人们会把他所有的窗户都砸掉。

- 依地语说



Forgot to say: it won''t cut the string for you, but will give you the
whereabouts of your substring. It should then be simple to extract it.

--
BR, Vladimir

If God lived on Earth, people would knock out all His windows.
-- Yiddish saying


这篇关于子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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