Last active
April 27, 2017 05:11
-
-
Save loganintech/7b603bc5d113ccccf43c0c1f8b3c11b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace std; | |
int main(int argc, char * argv[]){ | |
string test = "start|test|figghty | awdawdawd awdaa| awdawd|WAdawdawdawdawdawdw|awdend"; | |
int array_size = 0; | |
string * array = split(test, "|", array_size); | |
for(int i = 0; i < array_size; i++){ | |
cout << array[i] << endl; | |
} | |
return 0; | |
} | |
string * split(string source, string delim, int &array_size) { | |
int delim_offset = delim.length(); | |
int previous_delim = -delim_offset; | |
int array_location = 0; | |
string * destination = new string[1]; | |
do{ | |
extend_array(&destination, array_location); | |
destination[array_location++] = source.substr(previous_delim + delim_offset, source.find(delim, previous_delim + delim_offset) - previous_delim - 1); | |
previous_delim = source.find(delim, previous_delim + delim_offset); | |
} while (source.find(delim, previous_delim + delim_offset) != -1); | |
destination[array_location++] = source.substr(previous_delim + delim_offset, source.find(delim, previous_delim + delim_offset) - previous_delim - 1); | |
array_size = array_location; | |
return destination; | |
} | |
void extend_array(string ** source, int size){ | |
string * array = new string[size+1]; | |
for(int i = 0; i < size; i++){ | |
array[i] = *source[i]; | |
} | |
*source = array; | |
delete [] array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment