从串联字符串中提取值 [英] extracting values from a concatenated string

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

问题描述

/pre您好,谢谢您的帮助和建议,有了您的帮助,我现在可以在vc ++中做一些工作了. 他们的列表,其中包含以下详细信息
1-> 2334-> ms
2-> 3465->我们
5-> 5670-> ns
在这些值中,我只需要获取1,2334,ns值(不包括->)并分别存储在文件中即可. 请任何人能给我一个关于如何执行此操作的想法吗?

我在这里使用CString.."pre/

/pre"对不起,经过很长一段时间后,我在回覆您的答案,
谢谢您的帮助:),我有一些疑问

@christian:请解释一下字符串混搭是什么意思?并且要使用Mid func(),在此处输入的值不是恒定的,它是可变的.

@Pallini:我使用了您的代码,但未定义Tokenize func(),其错误提示为"Tokenize不是一个函数CString"?(我也没有在MSDN lib中找到一个名为Tokenize的cmd)您可以帮忙吗? br/>
谁能给我一个想法,分别提取值.."/pre

@ tush_2003:感谢您的建议,我正在我的代码中尝试它..但是它再次存储为连接字符串(不带--->),这是这三个值存储在单独变量中的任何函数吗? />
@DX Roster:Split函数未在vc ++中定义.

/pre "hello, thanks for your help and suggestion, with your help i am able to do some work in vc++.. now,i am stuck up with some coding..
their a list which contains following details
1-->2334-->ms
2-->3465-->us
5-->5670-->ns
in these values i need to fetch only 1,2334,ns values(excluding -->) and store in a file separately..
please can anyone give me an idea of how to do this??

i am using CString over here.." pre/

/pre""sorry, after long gap i am replying to your answers,
thanks for your help :) , i have got some doubts

@christian:could please explain what is string mashing means? And to use Mid func(), the values entered here are not constant, it varies..

@Pallini: i used your code but Tokenize func() is not defined, its giving error saying "Tokenize is not a function CString"?(also i didn find a cmd called Tokenize in MSDN lib)could you pls help in this?

can anyone give me an idea to extract values separately..""/pre

@tush_2003: thanks for your suggestion, i''m trying it in my code.. but again it stores as concatenated string (without--->),is thier any func where those three values stores in separate variables??

@DX Roster:Split func is not defined in vc++

推荐答案

您是指字符串列表吗?
如果您使用的是MFC,请查看CStringT::Tokenize [ ^ ]方法,例如:
Do you mean a list of strings?
If you are using MFC then look at CStringT::Tokenize [^] method, for instance:
CString str(_T("1-->2334-->ms"));
CString strField[3];
int index = 0;
strField[0] = str.Tokenize(_T("-->"), index);
strField[1] = str.Tokenize(_T("-->"), index);
strField[2] = str.Tokenize(_T("-->"), index);


:)


返回子字符串的CString函数称为 ^ ],假设位置足够固定,这比使用其他人提供的标记化代码要快.
The CString function to return a substring is called Mid[^], assuming that the positions are fixed enough that this is quicker than using the tokenisation code that someone else provided.


您可以使用字符串混搭来搜索索引第一个>和第一个-之后,请使用子字符串方法或按索引遍历字符以提取它们.具体细节实际上取决于您使用的字符串类.我大多数时候都尝试使用std :: string,但我认为大多数人都使用CString.

C ++没有内置正则表达式,boost库可能提供其中一个.如果您可以访问正则表达式,那将使其变得容易.在.NET中,字符串类的split方法也将使其变得微不足道.

话虽如此,在我看来,您的子字符串是固定位置,因此您只需将其拉出即可.如果您有13个字符,则只有一个数字,任何额外的字符都位于前面,因此您可以检查整个字符串的长度,然后从那里算出子字符串的位置.

如果我们要提供更具体的帮助,则需要编辑您的帖子并告诉我们使用哪种字符串类.
you can use string mashing to search for the index of the first > and the first - after that, then use a substring method or just walk over the characters by index to extract them. The specifics really depend on what string class you are using. I try to use std::string most of the time, but I think most people use CString.

There is no regex built in to C++, the boost library may offer one. If you could get access to regex, that would make it easy. In .NET, the split method of the string class would also make this trivial.

Having said that, it looks to me like your substring is a fixed position, so you can just pull it out. If you have 13 characters, you have a single digit, any extras are digits on the front, so you can check the whole string length then work out the position of your substring from there.

You need to edit your post and tell us what string class you use, if we''re going to give more specific help.


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

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