?? xstring.cpp
字號:
/**********************************************************
**
** 文件名: XString.cpp
**
** Copyright (c) 2002-2003 大雷公司技術開發部
**
** 創建人: 徐進林
**
** 日 期: 2002-07-05
**
** 修改人:
**
** 日 期:
**
** 描 述: 共用函數
**
** 版 本:
**
***********************************************************/
#include "StdAfx.h"
#include "XString.h"
/********************************************************************/
/** 功能: 得到隔離符號的個數(文本數) */
/** 參數: */
/** szString--查找的字符串 */
/** szSymbol--隔離符號 */
/** 返回值: */
/** int 類型結果 */
/********************************************************************/
int GetTextCountFromStringEx(CString szString, CString szSymbol)
{
int i;
int nSymbolCount,nFindPos;
nSymbolCount = 0;
nFindPos = 0;
if(szString.IsEmpty())
{
nSymbolCount = 0;
}
else if(szString.Right(1) != szSymbol)
{
szString += szSymbol;
}
for(i=0; i<szString.GetLength(); i++)
{
nFindPos = szString.Find(szSymbol, nFindPos);
if(nFindPos == -1)
{
break;
}
else
{
nSymbolCount++;
nFindPos++;
}
}
return nSymbolCount;
}
/********************************************************************/
/** 功能: 得到隔離符號的個數(文本數) */
/** 參數: */
/** szString--查找的字符串 */
/** 返回值: */
/** int 類型結果 */
/********************************************************************/
int GetTextCountFromString(CString szString)
{
int i;
int nSymbolCount,nFindPos;
CString szRet(""),szSymbol("");
unsigned char szSym[2];
szSym[0] = SYMBOL;
szSym[1] = 0x00;
szSymbol.Format(_T("%s"), szSym);
nSymbolCount = 0;
nFindPos = 0;
if(szString.IsEmpty())
{
nSymbolCount = 0;
}
else if(szString.Right(1) != szSymbol)
{
szString += szSymbol;
}
for(i=0; i<szString.GetLength(); i++)
{
nFindPos = szString.Find(szSymbol, nFindPos);
if(nFindPos == -1)
{
break;
}
else
{
nSymbolCount++;
nFindPos++;
}
}
return nSymbolCount;
}
/********************************************************************/
/** 功能: 得到第nIndex號的文本的位置 */
/** 參數: */
/** szString--查找的字符串 */
/** szSymbol--隔離符號 */
/** nIndex--索引號 */
/** 返回值: */
/** int 類型結果 */
/********************************************************************/
int GetTextPosFromString(CString szString, CString szSymbol, int nIndex)
{
int i;
int nSymbolCount,nFindPos;
int nRet;
nSymbolCount = 0;
nFindPos = 0;
nRet = -1;
if(nIndex < 1)
{
return -2;
}
if(szString.Right(1) != szSymbol)
{
szString += szSymbol;
}
for(i=0; i<szString.GetLength(); i++)
{
nFindPos = szString.Find(szSymbol, nFindPos);
if(nFindPos == -1)
{
break;
}
else
{
nSymbolCount++;
if(nSymbolCount == nIndex)
{
nRet = nFindPos;
break;
}
nFindPos++;
}
}
return nRet;
}
/********************************************************************/
/** 功能: 得到第nIndex號的文本 */
/** 參數: */
/** szString--查找的字符串 */
/** szSymbol--隔離符號 */
/** nIndex--索引號 */
/** 返回值: */
/** CString 類型結果 */
/********************************************************************/
CString GetTextFromStringEx(CString szString, CString szSymbol, int nIndex)
{
int nStartPos,nEndPos;
CString szRet("");
nStartPos = 0;
nEndPos = 0;
if(nIndex > 0)
{
nEndPos = GetTextPosFromString(szString, szSymbol, nIndex);
if(nEndPos > 0)
{
if(nIndex > 1)
{
nStartPos = GetTextPosFromString(szString, szSymbol, (nIndex - 1)) + 1;
}
}
}
//找到
if(nEndPos > 0)
{
szRet = szString.Mid(nStartPos, (nEndPos - nStartPos));
}
return szRet;
}
/********************************************************************/
/** 功能: 得到第nIndex號的文本 */
/** (本函數所查找的文本只有用SetTextToString() */
/** 加入的才能正確找到) */
/** 參數: */
/** szString--查找的字符串 */
/** nIndex--索引號 */
/** 返回值: */
/** CString 類型結果 */
/********************************************************************/
CString GetTextFromString(CString szString, int nIndex)
{
int nStartPos,nEndPos;
CString szRet(""),szSymbol("");
unsigned char szSym[2];
szSym[0] = SYMBOL;
szSym[1] = 0x00;
szSymbol.Format(_T("%s"), szSym);
nStartPos = 0;
nEndPos = 0;
if(nIndex > 0)
{
nEndPos = GetTextPosFromString(szString, szSymbol, nIndex);
if(nEndPos > 0)
{
if(nIndex > 1)
{
nStartPos = GetTextPosFromString(szString, szSymbol, (nIndex - 1)) + 1;
}
}
}
//找到
if(nEndPos > 0)
{
szRet = szString.Mid(nStartPos, (nEndPos - nStartPos));
}
return szRet;
}
/********************************************************************/
/** 功能: 把szText加入到得到szString中,其索引號為nIndex, */
/** 若發現nIndex號的文本已存在,則替換 */
/** 參數: */
/** szString--查找的字符串 */
/** szText--要加入到szString的文本 */
/** nIndex--索引號 */
/** 返回值: */
/** TRUE--成功 */
/** FALSE--失敗 */
/********************************************************************/
BOOL SetTextToString(CString &szString, CString szText, int nIndex)
{
int nStartPos,nEndPos;
int i,nCount;
CString szRet(""),szTemp(""),szSymbol("");
unsigned char szSym[2];
BOOL bRet;
szSym[0] = SYMBOL;
szSym[1] = 0x00;
bRet = FALSE;
nStartPos = 0;
nEndPos = 0;
szSymbol.Format(_T("%s"), szSym);
nCount = GetTextCountFromStringEx(szString, szSymbol);
if(nIndex < 1)
{
return FALSE;
}
else if(nIndex > nCount)
{
nCount = nIndex;
}
for(i=1; i<=nCount; i++)
{
szTemp = GetTextFromString(szString, i);
if(i == nIndex)
{
szTemp = szText;
}
szRet += (szTemp + szSymbol);
bRet = TRUE;
}
szString.Format(_T("%s"), szRet);
return bRet;
}
//得到第nIndex括號中的文本
BOOL GetTextOfBracketFromString(CString szString, int nIndex, CString &szText)
{
if(szString.IsEmpty() || (nIndex < 0))
{
return FALSE;
}
int nTimes = 1;
int nPos = -1;
int nPos1 = -1;
int nPos2 = -1;
nPos = szString.Find('(', 0);
while(nPos != -1)
{
if(nTimes == nIndex)
{
nPos1 = ++nPos;
nPos2 = szString.Find(')', nPos1);
break;
}
nTimes++;
nPos++;
nPos = szString.Find('(', nPos);
}
if((nPos2 < nPos1) || (nPos1 == -1))
{
return FALSE;
}
else if(nPos2 == nPos1)
{
szText = "";
return TRUE;
}
else
{
szText = szString.Mid(nPos1, nPos2 - nPos1);
return TRUE;
}
return FALSE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -