Split ๊ตฌํ
๐โโ๏ธSplit ๊ตฌํ
Split ํจ์๋ฅผ ์ง์ ๊ตฌํํ๊ธฐ.
delimiter๋ฅผ ๊ธฐ์ค์ผ๋ก ๋์ด์ ๋ฌธ์์ด ๋ฐฐ์ด๋ก ๋ง๋ค์ด์ฃผ๋ ํจ์.
vector<string> split(const string& input, string delimiter)
{
vector<string> result;
auto start = 0;
auto end = input.find(delimiter);
while (end != string::npos)
{
result.push_back(input.substr(start, end - start));
start = end + delimiter.size();
end = input.find(delimiter, start);
}
result.push_back(input.substr(start));
return result;
}
๐์ ์ฒด ์ฝ๋
vector<string> split(const string& input, string delimiter)
{
vector<string> result;
auto start = 0;
auto end = input.find(delimiter);
while (end != string::npos)
{
result.push_back(input.substr(start, end - start));
start = end + delimiter.size();
end = input.find(delimiter, start);
}
result.push_back(input.substr(start));
return result;
}