我想分割我的實際關鍵點,然後提取所有的領域後分裂它點。將字符串拆分爲點並從C++中提取所有字段?
我的鑰匙看起來像這樣的東西 -
@event.1384393612958.1136580077.TESTING
目前,我能夠分裂它點後只能提取第一場是@event
。現在如何提取所有其他字段。以下是我的代碼,目前我正在使用它從中提取第一個字段。
if (key)
{
char* first_dot = strchr(key, '.');
if (first_dot)
{
// cut at the first '.' character
first_dot[0] = 0;
}
}
cout << "Fist Key: " << key << endl;
然後提取單個字段後,第二個字段存儲爲uint64_t
,第三場爲uint32_t
和最後一個字段作爲string
。
更新: -
這是我已經得到了 -
if (key)
{
char *first_dot = strtok(key, ".");
char *next_dot = strtok(NULL, ".");
uint64_t secondField = strtoul(next_dot, 0, 10);
cout << first_dot << endl;
cout << secondField << endl;
}
從中我能提取第一和第二現場。第三和第四場呢?
「提取」字段是一兩件事要做,但你想要做什麼結果呢?存儲在什麼地方? – usr2564301
哎呀抱歉是,將它存儲在某處..讓我更新問題.. – AKIWEB
然後它是一個重複:http://stackoverflow.com/a/237280/912757 – Nil