Skip to content

Instantly share code, notes, and snippets.

@mia-0032
Created July 27, 2014 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mia-0032/dfbaa3a5326116488728 to your computer and use it in GitHub Desktop.
Save mia-0032/dfbaa3a5326116488728 to your computer and use it in GitHub Desktop.
mbed用の文字列加工関数
#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