-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
32 lines (28 loc) · 923 Bytes
/
util.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
#include <iostream>
#include <fstream>
#include <string>
//simple function that removes all non alphanumeric values in string, and changes original string to it
void stringstrip(std::string &str){
std::string retstr;
for(size_t i = 0; i< str.length();i++){
if (isalnum(str[i])) retstr += str[i];
}
str = retstr;
}
//simple function that removes all non alphanumeric values in string, and returns new string with changes
std::string newstringstrip(std::string str){
std::string retstr;
for(size_t i = 0; i< str.length();i++){
if (isalnum(str[i])) retstr += str[i];
}
return retstr;
}
//simple function for converting txt files to strings
std::string filetostring(std::string filelocation){
std::ifstream examplefile; examplefile.open(filelocation);
std::string retstr;
while (examplefile.good()){
retstr += examplefile.get();
}
return retstr;
}