SORU
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ş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • FASHTAG

    FASHTAG

    5 EYLÜL 2012
  • FUzzyBUnnyBOoties

    FUzzyBUnnyBO

    3 EKİM 2007
  • Jucyber Tutoriais

    Jucyber Tuto

    8 EYLÜL 2009