一个类似Java String[] split(String regex)的VC++函数
2010-06-13 13:14
387 查看
http://hi.baidu.com/ccskun/blog/item/9c4d033219ab5bfe1b4cff41.html/cmtid/1ce9b84445d57e2dcffca3d3
我也写了一个,
Int PA_CStringSplit(CString strSource, CString strSplitter, CStringArray &saDestination) {
INT m_iLen_source = strSource.GetLength();
INT m_iLen_splitter = strSplitter.GetLength();
INT iStart = 0;
INT iLen = 0;
INT iPos = 0;
saDestination.RemoveAll();
do {
iPos = strSource.Find(strSplitter, iStart);
if ( -1== iPos) {
iLen = m_iLen_source - iStart;
} else {
iLen = iPos - iStart;
}
saDestination.Add(strSource.Mid(iStart, iLen));
iStart += iLen + m_iLen_splitter;
} while (iStart < m_iLen_source);
return TRUE;
}
INT_PTR Split_CString(const CString& source,//需要截取的原字符串 CStringArray& dest,//分割后的字符串数组 const CString& division//用做分割符的字符串 )//使用方式:Split(strViewString, dest, "<div id="pro_detail">"); { if( source.IsEmpty() ) return -1; dest.RemoveAll(); int len = division.GetLength(); int iFirst = 0; int nCount = 0; int pos = 0; int pre_pos = -1; while( -1 != pos ) { if( -1 == pre_pos ) pos = source.Find(division,pos); else pos = source.Find(division,(pos+1)); if( -1 == pre_pos ) { iFirst = 0; if( -1 == pos ) nCount = source.GetLength(); else nCount = pos; } else { iFirst = pre_pos+len; if( -1 != pos ) nCount = pos - pre_pos - len; else nCount = source.GetLength()-pre_pos-len; } dest.Add(source.Mid(iFirst,nCount)); pre_pos = pos; } return dest.GetCount(); |
Int PA_CStringSplit(CString strSource, CString strSplitter, CStringArray &saDestination) {
INT m_iLen_source = strSource.GetLength();
INT m_iLen_splitter = strSplitter.GetLength();
INT iStart = 0;
INT iLen = 0;
INT iPos = 0;
saDestination.RemoveAll();
do {
iPos = strSource.Find(strSplitter, iStart);
if ( -1== iPos) {
iLen = m_iLen_source - iStart;
} else {
iLen = iPos - iStart;
}
saDestination.Add(strSource.Mid(iStart, iLen));
iStart += iLen + m_iLen_splitter;
} while (iStart < m_iLen_source);
return TRUE;
}
相关文章推荐
- 今天遇到的一个问题----java String.split( Regex )的误区
- Split区分一个或多个空格和java中List类型与String数组互相转换
- Java String.Split(String regex)方法之设置多个分隔符
- [每天一个知识点]11-Java语言-String.split
- JAVA中String.split的一个小例子
- 分享一个 Java String split 快速分割的方法
- java使用String.split方法时要注意的问题
- java网络编程(三):一个类似QQ的聊天程序
- java实现String的split方法
- 使用beanShell来解析执行java的String方法,类似javascipt的eval方法
- Java 字符串Split方法的一个坑
- JAVA String.split()方法
- 对java中的String采用+=连接字符串需要注意的一个问题
- JAVA String.split()方法
- java控制台程序如何判断String字符串中只输入了一个回车
- Java String.split()用法小结
- Java中String的split()方法的一些需要注意的地方
- java String.indexOf方法在一个字符串中查找另一个字符串的次数的简单应用
- java String.split丢失结尾空字符串的问题
- Java中String#split的坑