---
title: "按字符串分割字符串"
author: "dotcpp"
date: "2010-04-08T11:25:40Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-04-08T11:25:40Z"
id: 637768
url: "https://dotcpp.iteye.com/blog/637768"
---

```
void Split(const CString& content, const CString& pattern, std::vector<CString>& strlist)
{
	int iPos = content.Find(pattern), iStart = 0;
	int i = 0;
	while (iPos != -1)
	{
		strlist.push_back(content.Mid(iStart, iPos - iStart));
		iStart = iPos + pattern.GetLength();
		iPos = content.Find(pattern, iStart);
		i++;
	}
	if (iStart <= content.GetLength())
		strlist.push_back(content.Mid(iStart));
}
```