geniomhe-oop-dnapp/include/strutils.hpp

30 lines
768 B
C++
Raw Normal View History

2023-10-01 12:26:59 +02:00
#pragma once
#include <functional>
#include <string>
#include <vector>
#include <sstream>
void replace_all(std::string &str, char from, char to) {
for (unsigned int i=0; i < str.length(); i++) {
if (str[i] == from) {
str[i] = to;
}
}
}
std::vector<std::string> split_string(std::string &str, char delim) {
std::stringstream sstream(str);
std::vector<std::string> fields;
std::string item;
while (std::getline(sstream, item, delim)) {
fields.push_back(item);
}
return fields;
}
void uppercase_string(std::string &str) {
std::transform(str.cbegin(), str.cend(),
str.begin(), // write to the same location
[](unsigned char c) { return std::toupper(c); });
}