?? csv.cpp
字號:
// Csv.cpp: implementation of the CCsv class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.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;
}
//判斷是否有專用字符(引號、逗號、Tab符、回車、換行)
if(strSource.Find(_T("\"")) == -1 && strSource.Find(_T(",")) == -1
&& strSource.Find(_T("\t")) == -1
&& strSource.Find(_T("\n")) == -1 && strSource.Find(_T("\r")) == -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;
strStarget = _T("");
//空字符串
if(strSource.Compare(_T("")) == 0)
{
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 + -