求一个效率的找字符串字串的方法!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
一个字符串:
“aaaa bbbbbbbb ccccc ddddddddd eeeeeeee” (之间空格数量不定)
char *acFindSubString (CString p_pString, int p_iIdx)
{
}
想写个函数。。
p_pString 为传入的字符串 p_iIdx 为要取得的第几个子串
p_iIdx = 2 就返回 bbbbbbbb
= 4 就返回 ddddddddd
不知道有什么好的方法。。效率高点的
可以用任何api
[解决办法]
CString m_str = "aaaa bbbbbbbb ccccc ddddddddd eeeeeeee"; int num;cin >> num; // 你的p_iIdx参数CString temp = m_str; // 你的p_pStringtemp.TrimLeft();for(int i = num - 1; i > 0; i--){ int index = temp.Find(' '); temp = temp.Right(temp.GetLength() - index - 1); temp.TrimLeft();}temp = temp.Left(temp.Find(' '));cout << (LPCTSTR)temp << endl;