-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringExample.cpp
47 lines (39 loc) · 1.19 KB
/
StringExample.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
#include <string_view>
#include "educelab/core/utils/String.hpp"
using namespace educelab;
auto main() -> int
{
// Upper and lower case transformers
std::string upper{"The quick, brown fox."};
to_lower(upper);
std::cout << upper << "\n"; // the quick, brown fox.
to_upper(upper);
std::cout << upper << "\n"; // THE QUICK, BROWN FOX.
// Trim operations
std::cout << trim_left(" left") << "\n"; // left
std::cout << trim_right("right ") << "\n"; // right
std::cout << trim(" center ") << "\n"; // center
// Split space separated
for (const auto& s : split(" a b c ")) {
std::cout << s << " ";
}
std::cout << "\n";
// a b c
// Split comma separated
for (const auto& s : split("a,b,c", ",")) {
std::cout << s << " ";
}
std::cout << "\n";
// a b c
// Split multiple delimiters
for (const auto& s : split("a+b-c", "+", "-")) {
std::cout << s << " ";
}
std::cout << "\n";
// a b c
// Conversion to numeric types
std::cout << to_numeric<int>("3.14") << "\n"; // 3
std::cout << to_numeric<float>("3.14") << "\n"; // 3.14
}