使用2个输入变量拆分字符串,“startstr”和“endstr” [英] Splitting a String with 2 input variables, "beginstr" and "endstr"
问题描述
我想制作一个分割字符串函数,但它变得越来越复杂。
我想做的是用String,BeginStr和一个
EndStr变量,我希望它在char数组中返回它。
例如:
char teststr [255];
strcpy(teststr," test:blah;");
char returned_string [255];
strcpy(returned_string,splitstring(teststr," test:",";"));
和它的对象是return_string = = blah
>
有人可以帮助我吗?
谢谢,非常感谢帮助=)
< blockquote> 2008-09-02 19:31, ke *********** @ gmail.com 写道:
我想制作一个分裂字符串函数,但它变得越来越复杂。
我想要做的是使用String,BeginStr a创建一个函数和一个
EndStr变量,我希望它以char数组返回它。
例如:
char teststr [255];
strcpy(teststr," test:blah;");
char returned_string [255];
strcpy(returned_string,splitstring(teststr," test:",";"));
和它的返回值= blah >
有人能帮帮我吗?
当然,首先转储char数组并使用std :: string。然后阅读
std :: string :: find()和std :: string :: substr()。首先找到BeginStr
然后获取其后的所有内容的子字符串,然后在其中找到EndStr并且
返回它前面的所有内容。
-
Erik Wikstr ?? m
9月2日,2:07 * pm,Erik Wikstr?m< Erik-wikst ... @ telia.comwrote:
2008-09-02 19:31,kevineller ... @ gmail.com写道:
我想制作一个分裂字符串函数,但它变得越来越复杂。
我想做的是使用String,BeginStr和
EndStr变量创建一个函数,我想要它在char数组中返回它。
例如:
char teststr [255];
strcpy(teststr," test:blah;");
char returned_string [255];
strcpy(returned_string,splitstring(teststr," test:",") ;;"));
和它的返回值= blah
有人可以帮助我?
当然,首先转储char数组并使用std :: string。然后阅读
std :: string :: find()和std :: string :: substr()。首先找到BeginStr
然后获取其后的所有内容的子字符串,然后在其中找到EndStr并且
返回它前面的所有内容。
-
Erik Wikstr?m
好的我做到了,但我的字符串是:
" test1 = test1; test2 = test2;"
它找到test2,但它只找到FIRST;,所以它说'
EndStr在BeginStr之前,它没有正确地执行这个
,
任何补救措施?
我'对不起,我没有提到我需要从文本文件中解析整行
这些。
ke *********** @ gmail.com 写道:
我想制作一个分裂字符串函数,但它变得越来越复杂。
我想做的是用一个函数做一个函数String,BeginStr和一个
EndStr变量,我希望它以char数组的形式返回它。
例如:
char teststr [255];
strcpy(teststr," test:blah;");
char returned_string [255] ;
strcpy(returned_string,splitstring(teststr," test:" ,;,));
和它的对象是否= blah
如果您的编译器支持它,那么你可能对TR1常规
表达式感兴趣。
LR
I want to make a split string function, but it''s getting complicated.
What I want to do is make a function with a String, BeginStr and an
EndStr variable, and I want it to return it in a char array.
For example:
char teststr[255];
strcpy(teststr, "test:blah;");
char returned_string[255];
strcpy(returned_string, splitstring(teststr, "test:", ";"));
and it returned_string would = blah
can someone help me?
Thank you, help is much appreciated =)
On 2008-09-02 19:31, ke***********@gmail.com wrote:I want to make a split string function, but it''s getting complicated.
What I want to do is make a function with a String, BeginStr and an
EndStr variable, and I want it to return it in a char array.
For example:
char teststr[255];
strcpy(teststr, "test:blah;");
char returned_string[255];
strcpy(returned_string, splitstring(teststr, "test:", ";"));
and it returned_string would = blah
can someone help me?Sure, first dump the char arrays and use std::string. Then read up on
std::string::find() and std::string::substr(). Start by finding BeginStr
and get a substring of everything after it, then find EndStr in that and
return everything in front of it.
--
Erik Wikstr??m
On Sep 2, 2:07*pm, Erik Wikstr?m <Erik-wikst...@telia.comwrote:On 2008-09-02 19:31, kevineller...@gmail.com wrote:
I want to make a split string function, but it''s getting complicated.
What I want to do is make a function with a String, BeginStr and an
EndStr variable, and I want it to return it in a char array.
For example:
char teststr[255];
strcpy(teststr, "test:blah;");
char returned_string[255];
strcpy(returned_string, splitstring(teststr, "test:", ";"));
and it returned_string would = blah
can someone help me?
Sure, first dump the char arrays and use std::string. Then read up on
std::string::find() and std::string::substr(). Start by finding BeginStr
and get a substring of everything after it, then find EndStr in that and
return everything in front of it.
--
Erik Wikstr?mOk I did that, but my string here is:
"test1=test1; test2=test2;"
and it finds test2, but it only finds the FIRST ";", so it''s saying
that the EndStr is before the BeginStr, and it doesn''t do this
correctly,
any remedy?
I''m sorry I didn''t include that I needed to parse a whole line of
these from a text file.
ke***********@gmail.com wrote:I want to make a split string function, but it''s getting complicated.
What I want to do is make a function with a String, BeginStr and an
EndStr variable, and I want it to return it in a char array.
For example:
char teststr[255];
strcpy(teststr, "test:blah;");
char returned_string[255];
strcpy(returned_string, splitstring(teststr, "test:", ";"));
and it returned_string would = blah
If your compiler supports it, you might be interested in TR1 regular
expressions.
LR
这篇关于使用2个输入变量拆分字符串,“startstr”和“endstr”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!