将字符串解析为令牌 [英] Parsing a string into tokens

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

问题描述

嗨 我如何将文件分成令牌.
是否有任何方法可以基于字符串来解析输入文件?

花一些时间来了解字符串 [ strtok/wcstok [ ^ ]函数.您可以通过调用c_str将它们播放为字符串,但这确实有点麻烦.

2.您可以在CP C ++字符串工具包(StrTk)令牌生成器中找到为这样的字符串编写的令牌生成器. a> [ ^ ].我只是随机选择了一个-尚未使用过,因此您必须尝试一下,看看是否喜欢它.如果不是,您可以随时使用本文来帮助您创建自己的解决方案.

3.您可以使用Boost令牌生成器.这与第二种解决方案非常接近,但是,您可以使用Boost :) Boost ::令牌生成器 [ ^ ]

说了这么多,我不得不承认我只使用第一种方法.我猜想这些年来,它已经发展成我了:)祝您好运!


Hi How can i break a file into tokens.
Is there any method to parse the input file on basis of strings ?

解决方案

You can use "strtok" or "strtok_s" to tokenize the string.


Take some time to learn about string[^]s.


Well you have a couple of options to choose from:

1. Use the strtok/wcstok[^] functions. You can aplay them to strings by calling c_str, but it is a bit of a pain really.

2. You can get yourself a tokenizer written for strings like this one here at CP C++ String Toolkit (StrTk) Tokenizer[^]. I just picked this one at random - haven''t used it so you will have to give it a go and see if you like it. If not - you can always use the article to help you create your own solution.

3. You can use the Boost tokenizer. This is pretty close to the 2nd solution, but, you know, Boost :) Boost::Tokenizer[^]

Having said all of that I have to admit I only use the first approach. It has grown on me over the years I guess :) Best of luck to you!


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

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