-
Notifications
You must be signed in to change notification settings - Fork 2
/
stringOperations.h
40 lines (35 loc) · 966 Bytes
/
stringOperations.h
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
#include <iostream>
#include <fstream>
using namespace std;
class StringOperations{
public:
bool extCheck ( const string &fileName, string const &extension) {
// check the file extension ends with .txt
if (fileName.length() >= extension.length())
return (0 == fileName.compare (fileName.length() - extension.length(), extension.length(), extension));
else
return false;
}
void stringCleansing(string &inpStr) {
int i = 0;
int len = inpStr.length();
while(i < len){
if (!isalnum(inpStr[i]) && inpStr[i] != ' '){
inpStr.erase(i,1);
len--;
}else
i++;
}
}
string getFileData(string filePath) {
// ifstream object to access file data
ifstream dFile(filePath);
string retString,temp;
// accessing file data
while (dFile >> temp){
retString += string(" ") + temp;
}
stringCleansing(retString);
return retString;
}
};