Created
July 27, 2014 11:17
-
-
Save mia-0032/dfbaa3a5326116488728 to your computer and use it in GitHub Desktop.
mbed用の文字列加工関数
This file contains 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 <string> | |
#include <list> | |
// 文字列strからstart_strとend_strで囲まれた部分を抽出する。 | |
string match_slice(string str, string start_str, string end_str) | |
{ | |
int start_pos = str.find(start_str); | |
int end_pos = str.rfind(end_str); | |
return str.substr(start_pos + 1, end_pos - start_pos - 1); | |
} | |
// 文字列delimで文字列strを分割して返す。 | |
list<string> split(string str, string delim) | |
{ | |
list<string> result; | |
int pos; | |
while((pos = str.find_first_of(delim)) != str.npos) { | |
if(pos > 0) { | |
result.push_back(str.substr(0, pos)); | |
} | |
str = str.substr(pos + 1); | |
} | |
if(str.length() > 0) { | |
result.push_back(str); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment