将部分字符串复制到其他字符串中 [英] Copy Part of String Into Other Strings

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

问题描述

Hello Everyone,

这就是问题(我正在使用Visual c + + 6.0):

我有一个字符串:

string1 ="这& life" ;;

我想用''&''作为分隔符帮我解析这个字符串

变为3个字符串,以便:

string2 =''这个''

string3 =''是''

string4 =''life' '

thanx

和平

Sakitah

Hello Everyone,
Here''s the problem (I''m using Visual c++ 6.0):
I have a string:
string1 = "This&is&life";
and i want to use the ''&'' as a seperator to help me parse this string
into 3 strings so that:
string2 = ''This''
string3 = ''is''
string4 = ''life''
thanx
Peace
Sakitah

推荐答案

sakitah写道:
sakitah wrote:
大家好,

这就是问题(我使用的是Visual c + + 6.0):

我有一个字符串:
string1 =" This& is& life";
Hello Everyone,
Here''s the problem (I''m using Visual c++ 6.0):
I have a string:
string1 = "This&is&life";




什么样的字符串?一个std :: string或一个C风格的字符数组?

答案往往不同。


Brian

-

请为上下文引用足够的上一条消息。要从

Google执行此操作,请点击显示选项。并使用展开的

标题中显示的回复。



What kind of "string"? A std::string or a C-style array of characters?
The answer tends to be different.

Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.




" sakitah" < SA ********* @ yahoo.com>在消息中写道

news:11 ********************* @ g14g2000cwa.googlegro ups.com ...

"sakitah" <sa*********@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
大家好,

这里有问题(我正在使用Visual c + + 6.0):

我有一个字符串:
string1 = 这和&生活;

我希望使用''&''作为分隔符来帮助我将这个字符串解析成3个字符串,以便:

string2 =''这个''
string3 =''是''
string4 =''生活''
Hello Everyone,
Here''s the problem (I''m using Visual c++ 6.0):
I have a string:
string1 = "This&is&life";
and i want to use the ''&'' as a seperator to help me parse this string
into 3 strings so that:
string2 = ''This''
string3 = ''is''
string4 = ''life''



#include< ; iostream>

#include< sstream>

#include< string>


int main()

{

std :: string s1 =" This& is& life";

std :: string s2,s3,s4;

std :: istringstream iss(s1);


std :: getline(iss,s2,''&'');

std :: getline(iss,s3,''&'');

std :: getline(iss,s4,''&'');


s td :: cout<< s1<< ''\ n''

<< s2<< ''\ n''

<< s3<< ''\ n''

<< s4<< ''\ n'';


返回0;

}


-Mike


#include <iostream>
#include <sstream>
#include <string>

int main()
{
std::string s1 = "This&is&life";
std::string s2, s3, s4;
std::istringstream iss(s1);

std::getline(iss, s2, ''&'');
std::getline(iss, s3, ''&'');
std::getline(iss, s4, ''&'');

std::cout << s1 << ''\n''
<< s2 << ''\n''
<< s3 << ''\n''
<< s4 << ''\n'';

return 0;
}

-Mike


嗨Mike,


如果字符串很大,我们打算解析它并且

将它存储在一个向量中,

我们如何使用istringstream得到''&''的计数,以便我们可以运行

a循环将其放入向量中....?

i用string.find累了它,但它需要计算

positons但是它的长度非常好。


-Alex

Hi Mike,

In case the string is a large one, and we are planning to parse it and
store it in a vector,
how can we get the count of ''&'' using istringstream so that we can run
a loop to put it in a vector....?
i tired it with string.find but it required the calculation of
positons but its pretty lenghth one.

-Alex


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

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