在C ++中使用long String [英] Working on long String in C++

查看:62
本文介绍了在C ++中使用long String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个像这样的长字符串:


015EnvironmentData1 ........


我想从中读取前三个字符并将它们转换为

整数。这将是字段名称的长度,然后

有值。因此,如果我们采用上面的例子

015意味着15 - 所以我们将阅读下一个15字符开始于

E的EnvironmentData直到a。

转移它来变量说字段


然后我必须读取此字段的值,然后是

15个字符长的STring中的字段,在上述情况下是1。


我需要帮助解析字符串以便我可以获得所有

字段及其值。


这必须是C ++。我是新来的。请帮忙。


提前致谢

Hi,

I have one long String like this:

015EnvironmentData1........

I want to read first three character from it and convert them to
integer. This will be the length of the Name of the field and then
there is value. So if we take above example
015 means 15 - So we are going to read next 15 Character Starting with
E of "EnvironmentData" till "a".
Transfer it to come Variable say Field

Then I have to read the Value of this field which is followed by this
15 character long Field in the STring that is 1 in the above case.

I need help in Stripping of the String so that I can get all the
Fields and their values.

This has to be in C++. I am new at it. Please help.

Thanks in advance

推荐答案

ma *********** @ gmail.com 写道:

我有一个像这样的长字符串:


015EnvironmentData1 ........


我想读前三个字符从它并将它们转换为

整数。这将是字段名称的长度,然后

有值。因此,如果我们采取上面的例子


015意味着15 - 所以我们将阅读下一个15字符开始于

E的EnvironmentData直到a。

转移它来变量说字段


然后我必须读取此字段的值,然后是

15个字符长的STring中的字段,在上述情况下是1。


我需要帮助解析字符串以便我可以获得所有

字段及其值。


这必须是C ++。我是新来的。请帮忙。
I have one long String like this:

015EnvironmentData1........

I want to read first three character from it and convert them to
integer. This will be the length of the Name of the field and then
there is value. So if we take above example
015 means 15 - So we are going to read next 15 Character Starting with
E of "EnvironmentData" till "a".
Transfer it to come Variable say Field

Then I have to read the Value of this field which is followed by this
15 character long Field in the STring that is 1 in the above case.

I need help in Stripping of the String so that I can get all the
Fields and their values.

This has to be in C++. I am new at it. Please help.



类似


std :: string const blah(" 015EnvironmentData1 ........" );

int n = -1;

std :: ostringstream os(blah.substr(0,3));

os> ; n;

std :: string Field = blah.substr(3,n);

os.str()= blah.substr(3 + n,1) ;

int值= -1;

os>值;


这是未经测试的,仅用于提供一个想法。


V

-

请在通过电子邮件回复时删除资金'A'

我没有回复最热门的回复,请不要问

Something like

std::string const blah("015EnvironmentData1........");
int n = -1;
std::ostringstream os(blah.substr(0, 3));
os >n;
std::string Field = blah.substr(3, n);
os.str() = blah.substr(3 + n, 1);
int Value = -1;
os >Value;

This is untested and only intended to give an idea.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


你好Victor,


感谢您的回复。


此字符串以指针形式进入解析函数

到字符串。能否请您提供类似上述

解决方案的建议,该解决方案适用于指向字符串的指针。


谢谢
Hi Victor,

Thanks for reply.

This String is coming to the Parsing function in the form of pointer
to the string. Could you please advice something like the above
solution that will work with Pointer to String.

Thanks


ma***********@gmail.com 写道:
ma***********@gmail.com wrote:

此字符串以指针形式进入解析函数

到字符串。您能否提供类似上述

解决方案的建议,该解决方案适用于Pointer to String。
This String is coming to the Parsing function in the form of pointer
to the string. Could you please advice something like the above
solution that will work with Pointer to String.



std :: string const blah(Pointer_To_String);


其他几乎完全一样。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

std::string const blah(Pointer_To_String);

Everyting else is pretty much the same.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于在C ++中使用long String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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