10 EYLÜL 2008, ÇARŞAMBA
Nasıl C bir dize tokenize ?
Java split uygun bir yöntem vardır:
String str = "The quick brown fox";
String[] results = str.split(" ");
Kolay bir şekilde C bunu yapmak için var mı ?
CEVAP
11 EYLÜL 2008, PERŞEMBE
Boost tokenizer sınıfı bu tür bir şey oldukça basit
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
int main(int, char**)
{
string text = "token, test string";
char_separator<char> sep(", ");
tokenizer< char_separator<char> > tokens(text, sep);
BOOST_FOREACH (const string& t, tokens) {
cout << t << "." << endl;
}
}
C 11 güncelleme:
#include <iostream>
#include <string>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
int main(int, char**)
{
string text = "token, test string";
char_separator<char> sep(", ");
tokenizer<char_separator<char>> tokens(text, sep);
for (const auto& t : tokens) {
cout << t << "." << endl;
}
}
Bunu Paylaş:
Nasıl bir dize başka bir dize içeriyor...
Nasıl doğru ActionScript 3 SOAP web se...
Nasıl JavaScript ile boş bir dize için...
Bir dize kontrol etmek için nasıl &quo...
Nasıl Bash dize değişkenleri bitiştirm...