wchar_t OrderingCode[100];
api的一些代码
string looks like this L"AAAA-1-3-5-5\n\r\BBB-A-3-6-6-4"
我需要在换行符中将字符串拆分为2。我只在ppl循环数组时找到样本。任何api函数都可以在C#
中用作String.Splitm_Result.SetWindowTextW(OrderingCode1);
m_Result.SetWindowTextW(OrderingCode2);
答案 0 :(得分:0)
使用std::string然后您可以轻松地按如下方式拆分它:
std::vector< std::wstring > SplitString( const std::wstring& str, wchar_t ch )
{
std::vector< std::wstring > ret;
size_t startPos = 0;
size_t endPos = str.find( ch, startPos );
while( endPos != std::wstring::npos )
{
ret.push_back( str.substr( startPos, endPos ) );
startPos = endPos + 1;
endPos = str.find( ch, startPos );
}
ret.push_back( str.substr( startPos, str.length() );
return ret;
}
答案 1 :(得分:0)
wchar_t * test, *next_token1;
test = wcstok_s(OrderingCode, L"\n\r", &next_token1);
if (test != NULL)
{
m_Result.SetWindowTextW(test);
test = wcstok_s(nullptr, L"\n\r", &next_token1);
if (test != NULL)
{
m_Result2.SetWindowTextW(test);
}
}