📄 csv.cpp
字号:
// Csv.cpp: implementation of the CCsv class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CIG.h"
#include "Csv.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCsv::CCsv()
{
}
CCsv::~CCsv()
{
}
CString CCsv::StrToCsv(const CString &strSource, CString &strStarget)
{
INT wSourceIndex = 0;
INT wNextSourceIndex = 0;
//空字符串
if(strSource.Compare(_T("")) == 0)
{
strStarget = _T("");
return strStarget;
}
//判断是否有专用字符
if(strSource.Find(_T("\"")) == -1 && strSource.Find(_T(",")) == -1)
{
strStarget = strSource;
return strStarget;
}
//文本声明开始
strStarget = _T("\"");
//将原串中的"扩展为""
wNextSourceIndex = strSource.Find(_T("\""), wSourceIndex);
while(wNextSourceIndex != -1)
{
strStarget += strSource.Mid(wSourceIndex, wNextSourceIndex - wSourceIndex + 1);
strStarget += _T("\"");
wSourceIndex = wNextSourceIndex + 1;
wNextSourceIndex = strSource.Find(_T("\""), wSourceIndex);
}
//加入剩下的字符串
strStarget += strSource.Mid(wSourceIndex);
//文本声明结束
strStarget += _T("\"");
return strStarget;
}
CString CCsv::CsvToStr(const CString &strSource, CString &strStarget)
{
INT wSourceIndex = 0;
INT wNextSourceIndex = 0;
//空字符串
if(strSource.Compare(_T("")) == 0)
{
strStarget = _T("");
return strStarget;
}
//判断是否有文本声明标志
if(strSource.Mid(0,1) != _T("\""))
{
strStarget = strSource;
return strStarget;
}
//去掉头文本声明开始标志
wSourceIndex = 1;
//将原串中的""减为"
wNextSourceIndex = strSource.Find(_T("\"\""), wSourceIndex);
while(wNextSourceIndex != -1)
{
strStarget += strSource.Mid(wSourceIndex, wNextSourceIndex - wSourceIndex + 1);
wSourceIndex = wNextSourceIndex + 2;
wNextSourceIndex = strSource.Find(_T("\"\""), wSourceIndex);
}
//加入剩下的字符串
wNextSourceIndex = strSource.Find(_T("\""), wSourceIndex);
if(wNextSourceIndex == -1) //错误的CSV格式,没有文本结束声明
{
strStarget += strSource.Mid(wSourceIndex);
return strStarget;
}
strStarget += strSource.Mid(wSourceIndex, wNextSourceIndex - wSourceIndex);
return strStarget;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -