C++ 分割字符串
来源:互联网 发布:园林设计用什么软件 编辑:程序博客网 时间:2024/05/21 10:08
按照标识符分割字符串,分割好的字段保存至数组,贴出示例代码:
#include <iostream>#include <string>#include <vector>using namespace std;std::vector<std::wstring> split_string(std::wstring &szInput, std::wstring &szToken){std::vector<std::wstring> result;int pos = 0;int begin = 0;const int size = szToken.size();while(true){if ((pos=szInput.find(szToken,begin))==std::wstring::npos){result.push_back(szInput.substr(begin));return result;}result.push_back(szInput.substr(begin, pos-begin));begin = pos + size;}}int main (){wstring szInput = L"hello$yy.com$this$is$test$by$kandy";std::vector<wstring> data = split_string(szInput, wstring(L"$"));for (int i=0; i<data.size(); ++i){wcout << data[i].c_str() << endl;//printf("%ls\r\n", data[i].c_str());}return 0;}
0 0
- 字符串分割(C/C++)
- C字符串分割
- C字符串分割
- C++MFC分割字符串
- 分割字符串(C版本)
- 字符串分割(C++)
- 字符串分割(C++)
- 字符串分割(C++)
- 字符串分割(C++)
- 字符串分割(C++)
- C字符串分割
- 字符串分割(C++)
- 字符串分割(C++)
- 常用字符串分割(C++)
- C语言字符串分割
- 字符串分割(C++)
- 字符串分割(C++)
- 字符串分割(C++)
- 懒人的第一篇博客喔
- docker ubuntu容器更换阿里源
- Check failed: error == cudaSuccess (8 vs. 0) invalid device function
- VS 调用 Matlab (混合编程)
- Error:Makefile:1449:*** mixed implicit and normal rules: deprecated syntax
- C++ 分割字符串
- 欧几里德算法求最大公约数
- maven中央仓库不能访问的解决办法
- leetcode之旅(9)-Reverse Linked List
- 在线旅游产品目前有哪些急需解决的痛点?
- 机器学习实战之决策树
- 设计模式:外观模式(Facade)
- 类和对象
- QProcess与外部程序的调用