本文整理汇总了C++中irr::core::stringw::subString方法的典型用法代码示例。如果您正苦于以下问题:C++ stringw::subString方法的具体用法?C++ stringw::subString怎么用?C++ stringw::subString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类irr::core::stringw
的用法示例。
在下文中一共展示了stringw::subString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
/** Splits a string into substrings separated by a certain character, and
* returns a std::vector of all those substring. E.g.:
* split("a b=c d=e",' ') --> ["a", "b=c", "d=e"]
* This is the version for wide strings.
* \param s The string to split.
* \param c The character by which the string is split.
*/
std::vector<irr::core::stringw> split(const irr::core::stringw& s, char c,
bool keepSplitChar)
{
try
{
std::vector<irr::core::stringw> result;
irr::s32 start = 0;
while (start < (irr::s32)s.size())
{
irr::s32 i = s.findNext(c, start);
if (i != -1)
{
if (keepSplitChar)
{
int from = start-1;
if (from < 0) from = 0;
result.push_back( s.subString(from, i-from) );
}
else result.push_back( s.subString(start, i-start) );
start = i+1;
}
else
{
if (keepSplitChar)
result.push_back( s.subString(start - 1,
s.size()-start + 1) );
else
result.push_back( s.subString(start, s.size()-start) );
return result;
//start = i+1;
}
}
return result;
}
catch (std::exception& e)
{
(void)e; // avoid warning about unused variable
Log::fatal("StringUtils",
"Fatal error in split(stringw) : %s @ line %i : '%s'.",
__FILE__, __LINE__, e.what());
exit(1);
}
} // split