-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplit_Function.cpp
More file actions
75 lines (55 loc) · 1.61 KB
/
Copy pathSplit_Function.cpp
File metadata and controls
75 lines (55 loc) · 1.61 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
using namespace std;
bool isDelimeter(string del, char c){
for(int i=0;i<del.length();i++){
if(del[i] == c) return true;
}
return false;
}
int wordCount(string del, string toChange){
int i=0;
int wordCount = 0;
bool cancelWordCountInc = false;
while(i!=toChange.length()){
if(isDelimeter(del,toChange[i])){
cancelWordCountInc = false;
}else if(!isDelimeter(del,toChange[i]) && cancelWordCountInc == false){
wordCount++;
cancelWordCountInc = true;
}
i++;
}
return wordCount;
}
string* split(string del, string toChange){
int numberOfWords = wordCount(del,toChange);
string* stringArray = new string[numberOfWords];
string addingString = "";
int counter = 0,i=0;
while(i!=toChange.length()){
if(isDelimeter(del,toChange[i]) && addingString!=""){
stringArray[counter] = addingString;
addingString = "";
counter++;
}else if(!isDelimeter(del,toChange[i])){
addingString = addingString + toChange[i];
}
i++;
if(addingString!="" && i == toChange.length()){
stringArray[counter] = addingString;
break;
}
}
return stringArray;
}
int main()
{
string str = " DDThis..is test.exampleDDD.,for.deleting . usingDDD delimeters..,Finish,..Of.The..Example,,";
string del = " .D,";
string* arrayOfWords = split(del,str);
for(int i=0;i<wordCount(del,str);i++){
cout << arrayOfWords[i] << endl;
}
delete[] arrayOfWords;
return 0;
}