Last active
March 18, 2022 03:16
-
-
Save DJmong/591a676df7357a83b763830067d17ca7 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
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <algorithm> | |
| std::vector<std::string> parseLine(std::string input, std::string del) | |
| { | |
| std::vector<std::string> result; | |
| std::string parse = ""; | |
| for(size_t idx = 0; idx < input.size(); ++idx) | |
| { | |
| if(find(del.begin(), del.end(), input[idx]) == del.end()) | |
| { | |
| parse += input[idx]; | |
| } | |
| else if(!parse.empty()) | |
| { | |
| result.push_back(parse); | |
| parse = ""; | |
| } | |
| if(idx+1 == input.size() && !parse.empty()) | |
| { | |
| result.push_back(parse); | |
| } | |
| } | |
| return result; | |
| } | |
| int main() | |
| { | |
| std::string input = "this,is!parse$test"; | |
| std::vector<std::string> result = parseLine(input, ",!$"); | |
| for(size_t idx = 0; idx < result.size(); ++idx) | |
| { | |
| std::cout << result[idx] << std::endl; | |
| } | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment