⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vb6functions.cpp

📁 VB6 has two very useful string functions: Join and Split. This code implements Join and Split functi
💻 CPP
字号:
#include "stdafx.h"
#include "VB6functions.h"

namespace VB6
{

CString ReadUntil(CString &sIn,const CString &sDelim,bool &bFound);

CString Join(const std::vector<CString> &source,const CString sDelim)
{
	CString sOut; long iC,Ubound;

  Ubound = source.size()-1;
	for(iC=0; iC<=Ubound-1; iC++)
		sOut += source.at(iC) + sDelim;

	sOut += source.at(iC);
	return sOut;
}

// split sIn using the delimeter sDelim. Put result array into vector
std::vector<CString> Split(CString sIn,const CString sDelim,const long nLimit)
{
	CString sRead; std::vector<CString> vecOut;
	long nC = 0; bool bFound;
	while(1)
	{
		nC++; 
		sRead = ReadUntil(sIn,sDelim,bFound);
		if(!bFound)
			break;
		vecOut.push_back(sRead);
		if(nLimit != -1 && nC >= nLimit)
			return vecOut;
	};
  vecOut.push_back(sIn);
	return vecOut;
}

CString ReadUntil(CString &sIn,const CString &sDelim,bool &bFound)
{
	long nPos; CString sOut;

	nPos = sIn.Find(sDelim);
	if(nPos>-1)
	{
     sOut = sIn.Left(nPos);
		 sIn = sIn.Mid(nPos + sDelim.GetLength()); 
		 bFound = true;
	}
	else bFound = false;
	return sOut;
}

// Replace sFind with sReplace
// nStart can be 0 - sIn.GetLength()-1 (char indexes start from 0 in VC, not 1 as in VB)
CString Replace(const CString sIn,const CString sFind, const CString sReplace,
								const long nStart, const long nCount)
{
	CString sOut; long nC=0,nPos;

	sOut = sIn;
	nPos = sOut.Find(sFind,nStart); //we miss vbCombare :(
	if(nPos<0) 
		return sOut;
	do {
		nC++;
		sOut = sOut.Left(nPos) + sReplace + sOut.Mid(nPos + sFind.GetLength());
		if(nCount != -1 && nC >= nCount) 
			break;
		nPos = sOut.Find(sFind,nStart);
	}	while(nPos>-1);
	return sOut;
}

} // namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -