解析逗号分隔的文本字符串 [英] parse comma delimited text string

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

问题描述

在MS VC ++ Express中我需要知道如何从一个逗号分隔的

文本字符串到多个字符串。


来自:

main_string =" onE,Two,Three,fouR,five,six


到这些:


string1 =" one"

string2 =" two"

string4 =" four" ;

string5 =" five"

string6 =" six"


需要移除空白区域case需要全部上限

或更低。

结果需要是字符串而不是内存中的指针或地址

所以我可以测试:


string test =" three"


if(three ==" three")

>
一些getlines只会有两个字符串,有些可能最多10个

请帮助举例,你输入的确切语法非常好

赞赏


我一直在努力不使用指针,但每次我最终使用它们都是



提前谢谢

in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.

from this:

main_string = "onE,Two,Three , fouR,five, six "

to these:

string1 = "one"
string2 = "two"
string3 = "three"
string4 = "four"
string5 = "five"
string6 = "six"

the white space needs to be removed and the case needs to be all upper
or lower.
The result needs to be strings and not pointers or addresses in memory
so I can test:

string test = "three";

if (three == "three")

some getlines will only have two strings some may have up to 10
Please help with examples, you input with exact syntax is greatly
appreciated

I have been struggling with not using pointers but every time I end up
using them.

Thanks in advance

推荐答案

electrixnow写道:
electrixnow wrote:
在MS VC ++ Express中我需要知道如何从一个逗号分隔的
文本字符串到许多字符串。

来自:
main_string =" onE,Two,Three,fouR,five,six

这些:

string1 =" one"
string2 =" two"
string3 =" three"
string4 =" four"
string5 = five
string6 =" six"

为此,有几个选项是好老的C strtok,或者

std :: string找到会员。

白色空间需要拆除,箱子需要全部更高或更低。
in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.

from this:

main_string = "onE,Two,Three , fouR,five, six "

to these:

string1 = "one"
string2 = "two"
string3 = "three"
string4 = "four"
string5 = "five"
string6 = "six"
For this, a couple of options are the good old C strtok, or the
std::string find members.
the white space needs to be removed and the case needs to be all upper
or lower.




见toxxxx()和isxxx()函数。


看起来太像家庭作业了给我...


-

Ian Collins。



See toxxxx() and isxxx() functions.

Looks too much like homework to me...

--
Ian Collins.


Howework,甚至不关闭。我是一个42岁的EE,而不是真正的
程序员。我有一个应用程序来应用它。我正在尝试

来比较两个数据文件并创建第三个以让我的部门知道

当新的绘图版本准备就绪时。我试过strtok,并且

strtok_s但这些函数总是创建指针。如果我知道如何轻松地将它们更改回STRINGS进行字符串比较,那就没问题了。通过

的方式,我们有相同的姓氏,这很奇怪。


已经失学多年了!


我所做的唯一编码就是80年代出生的玉米和c壳。 C ++

是如此强大,我想了解更多。我刚刚购买了一本没有恐惧的书。如果您对VC ++的书籍有任何建议

请告诉我。


比较文本字符串的最佳方法是:


if(" test string" == pointer_returned_from_strtok)


将让我朝着正确的方向前进。


谢谢!

Howework, not even close. I am an 42 year old EE and not really a
programmer. I have an application at work to apply this to. I am trying
to compare two data files and create a third to let my department know
when new releases for drawing are ready. I have tried strtok, and
strtok_s but those functions allways create pointers. That is fine if I
knew how to easly change them back to STRINGS for string comparison. By
the way we have the same last name, that''s wierd.

been out of school for too many years!

The only coding I have done was born, corn and c shell in the 80''s. C++
is so much more robust, I am trying to learn more. I just purchased a
book C++ without fear. If you have any suggestions for books for VC++
let me know.

what is the best way to compare text strings like this:

if ( "test string" == pointer_returned_from_strtok )

that will get me going in the right directions.

Thanks!


electrixnow写道:
electrixnow wrote:
Howework,甚至没有关闭。我是一个42岁的EE,并不是一个真正的程序员。我有一个应用程序来应用它。我正在尝试比较两个数据文件并创建第三个以让我的部门知道
何时准备好新的绘图版本。我试过strtok,并且strtok_s但这些函数总是创建指针。如果我知道如何轻松地将它们更改回STRINGS以进行字符串比较,那就没问题了。


#include< string>

#include< iostream>


int main(){

// C样式字符串

char mystring [] =" hello world" ;;


//指向null终止的指针令牌

char * token = mystring + 6;


//从令牌创建字符串

std :: string newString(令牌) );


if(newString ==" world"){

std :: cout<< 比较真实 << std :: endl;

} else {

std :: cout<< 比较Fasle << std :: endl;

}

}

我所做的唯一编码就是80年代诞生的玉米和c壳。 C ++
非常强大,我想了解更多。我只是毫不畏惧地购买了一本书C ++。如果您对VC ++的书籍有任何建议,请告诉我。


加速C ++,来自Koenig和Moo。

比较这样的文本字符串的最佳方法是:

if( " test string" == pointer_returned_from_strtok)


//动态创建字符串

if(" test string" == std :: string( pointer_returned_from_strtok))

将让我朝着正确的方向前进。
Howework, not even close. I am an 42 year old EE and not really a
programmer. I have an application at work to apply this to. I am trying
to compare two data files and create a third to let my department know
when new releases for drawing are ready. I have tried strtok, and
strtok_s but those functions allways create pointers. That is fine if I
knew how to easly change them back to STRINGS for string comparison. By
#include <string>
#include <iostream>

int main() {
// C style string
char mystring[] = "hello world";

// pointer to null terminated token
char* token = mystring + 6;

// create string from token
std::string newString(token);

if (newString == "world") {
std::cout << "Comparison True" << std::endl;
} else {
std::cout << "Comparison Fasle" << std::endl;
}
}
The only coding I have done was born, corn and c shell in the 80''s. C++
is so much more robust, I am trying to learn more. I just purchased a
book C++ without fear. If you have any suggestions for books for VC++
let me know.
Accelerated C++, by Koenig and Moo.
what is the best way to compare text strings like this:

if ( "test string" == pointer_returned_from_strtok )
// create string on the fly
if ("test string" == std::string(pointer_returned_from_strtok))
that will get me going in the right directions.




关闭你去吧! :)


Ben Pope

-

我不仅仅是一个数字。对很多人来说,我被称为字符串...



Off you go then! :)

Ben Pope
--
I''m not just a number. To many, I''m known as a string...


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

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