mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2066 Observed Data : Split string by delimiter
This commit is contained in:
parent
9d06ef857e
commit
6444b9f32e
@ -67,3 +67,15 @@ double RiaStdStringTools::toDouble(const std::string& s)
|
||||
|
||||
return doubleValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<std::string> RiaStdStringTools::splitStringBySpace(const std::string& s)
|
||||
{
|
||||
std::vector<std::string> words;
|
||||
|
||||
splitByDelimiter(s, words);
|
||||
|
||||
return words;
|
||||
}
|
||||
|
@ -18,7 +18,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@ -31,5 +35,19 @@ public:
|
||||
|
||||
static int toInt(const std::string& s);
|
||||
static double toDouble(const std::string& s);
|
||||
|
||||
static std::vector<std::string> splitStringBySpace(const std::string& s);
|
||||
|
||||
private:
|
||||
template <class Container>
|
||||
static void splitByDelimiter(const std::string& str, Container& cont, char delimiter = ' ')
|
||||
{
|
||||
std::stringstream ss(str);
|
||||
std::string token;
|
||||
while (std::getline(ss, token, delimiter))
|
||||
{
|
||||
cont.push_back(token);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user