|
通常、以下のように使用します
Buff->Trim( " " ) の " " は半角と全角のスペースです
|
|
| // *********************************************************
// 文字列を指定した文字で囲む
// 既にその文字で囲まれている場合はなにもしない
// 戻り値 : 無し
// *********************************************************
void LboxStringEnclose( LPTSTR pszBuffer, int c )
{
if ( pszBuffer[0] == (char)c &&
pszBuffer[lstrlen(pszBuffer)-1] == (char)c ) {
return;
}
pszBuffer[lstrlen(pszBuffer)+1] = 0x00;
pszBuffer[lstrlen(pszBuffer)+2] = 0x00;
MoveMemory( pszBuffer + 1, pszBuffer, lstrlen( pszBuffer ) );
pszBuffer[0] = (char)c;
pszBuffer[lstrlen(pszBuffer)] = (char)c;
}
void LboxString::Enclose( LPTSTR pszBuffer, int c )
{
LboxStringEnclose( pszBuffer, c );
}
void LboxString::Enclose( int c )
{
LboxStringEnclose( LboxString::szLboxString, c );
}
void LboxStringEnclose( LPTSTR pszBuffer, int c1, int c2 )
{
if ( pszBuffer[0] == (char)c1 &&
pszBuffer[lstrlen(pszBuffer)-1] == (char)c2 ) {
return;
}
pszBuffer[lstrlen(pszBuffer)+1] = 0x00;
pszBuffer[lstrlen(pszBuffer)+2] = 0x00;
MoveMemory( pszBuffer + 1, pszBuffer, lstrlen( pszBuffer ) );
pszBuffer[0] = (char)c1;
pszBuffer[lstrlen(pszBuffer)] = (char)c2;
}
void LboxString::Enclose( LPTSTR pszBuffer, int c1, int c2 )
{
LboxStringEnclose( pszBuffer, c1, c2 );
}
void LboxString::Enclose( int c1, int c2 )
{
LboxStringEnclose( LboxString::szLboxString, c1, c2 );
}
| |
|
|
|
| // *********************************************************
// 文字列が指定した文字で囲まれていたらその文字を取り去る
// 戻り値 : 無し
// *********************************************************
void LboxStringRemoveEnclose( LPTSTR pszBuffer, int c )
{
if ( pszBuffer[0] == (char)c &&
pszBuffer[lstrlen(pszBuffer)-1] == (char)c ) {
MoveMemory( pszBuffer, pszBuffer + 1, lstrlen( pszBuffer ) );
pszBuffer[lstrlen(pszBuffer)-1] = 0x00;
}
}
void LboxString::RemoveEnclose( LPTSTR pszBuffer, int c )
{
LboxStringRemoveEnclose( pszBuffer, c );
}
void LboxString::RemoveEnclose( int c )
{
LboxStringRemoveEnclose( LboxString::szLboxString, c );
}
void LboxStringRemoveEnclose( LPTSTR pszBuffer, int c1, int c2 )
{
if ( pszBuffer[0] == (char)c1 &&
pszBuffer[lstrlen(pszBuffer)-1] == (char)c2 ) {
MoveMemory( pszBuffer, pszBuffer + 1, lstrlen( pszBuffer ) );
pszBuffer[lstrlen(pszBuffer)-1] = 0x00;
}
}
void LboxString::RemoveEnclose( LPTSTR pszBuffer, int c1, int c2 )
{
LboxStringRemoveEnclose( pszBuffer, c1, c2 );
}
void LboxString::RemoveEnclose( int c1, int c2 )
{
LboxStringRemoveEnclose( LboxString::szLboxString, c1, c2 );
}
| |
|
LboxStringRemoveEnclose
|
|
| // *********************************************************
// 文字列の挿入
// 戻り値 : 文字列へのポインタ
// *********************************************************
LPTSTR LboxString::Insert( LboxString *LString )
{
return LboxString::Insert( LString->szLboxString );
}
LPTSTR LboxString::Insert( LPTSTR lpBuffer )
{
DWORD nSize;
nSize =
lstrlen(LboxString::szLboxString) +
lstrlen( lpBuffer ) + 1;
if ( nSize > LboxString::nLboxString ) {
LboxString::nLboxString = nSize;
LboxReAlloc(
&(LboxString::szLboxString),
LboxString::nLboxString
);
}
MoveMemory(
(LboxString::szLboxString) + lstrlen( lpBuffer ),
LboxString::szLboxString,
lstrlen(LboxString::szLboxString)+1
);
MoveMemory(
(LboxString::szLboxString),
lpBuffer,
lstrlen(lpBuffer)
);
return (LboxString::szLboxString);
}
LPTSTR LboxString::Insert( LboxString *LString, int nPos )
{
return LboxString::Insert( LString->szLboxString, nPos );
}
LPTSTR LboxString::Insert( LPTSTR lpBuffer, int nPos )
{
DWORD nSize;
nSize =
lstrlen(LboxString::szLboxString) +
lstrlen( lpBuffer ) + 1;
if ( nSize > LboxString::nLboxString ) {
LboxString::nLboxString = nSize;
LboxReAlloc(
&(LboxString::szLboxString),
LboxString::nLboxString
);
}
MoveMemory(
(LboxString::szLboxString) + nPos + lstrlen( lpBuffer ),
LboxString::szLboxString + nPos,
lstrlen(LboxString::szLboxString)+1-nPos
);
MoveMemory(
(LboxString::szLboxString)+nPos,
lpBuffer,
lstrlen(lpBuffer)
);
return (LboxString::szLboxString);
}
| |
|
|
|
| // *********************************************************
// 指定文字列置き換え
// 戻り値 : 無し
// *********************************************************
LPTSTR LboxString::Replace( LPTSTR lpTarget, LPTSTR lpReplace )
{
DWORD nTarget,nReplace,nUpsize;
nTarget = lstrlen( lpTarget );
nReplace = lstrlen( lpReplace );
nUpsize = 0;
LboxString *LString;
if ( nTarget < nReplace ) {
LString = new LboxString( LboxString::nLboxString + MAX_PATH );
}
else {
LString = new LboxString( LboxString::nLboxString );
}
unsigned char *base;
base = (unsigned char *)LboxString::szLboxString;
unsigned char *ptr;
ptr = _mbsstr(
base,
(const unsigned char *)lpTarget
);
if ( ptr != NULL ) {
DWORD dwNew;
dwNew = 0;
while( ptr != NULL ) {
if ( nTarget < nReplace ) {
nUpsize += nReplace - nTarget;
if ( nUpsize > MAX_PATH ) {
LString->Resize(
LString->nLboxString + MAX_PATH
);
nUpsize = 0;
nUpsize += nReplace - nTarget;
}
}
CopyMemory(
LString->szLboxString+dwNew,
(LPTSTR)base,
(DWORD)ptr - (DWORD)base
);
dwNew = dwNew + (DWORD)ptr - (DWORD)base;
CopyMemory(
LString->szLboxString+dwNew,
lpReplace,
nReplace
);
dwNew = dwNew + nReplace;
LString->szLboxString[dwNew] = 0x00;
base = ptr + nTarget;
ptr = _mbsstr(
base,
(const unsigned char *)lpTarget
);
}
lstrcat( LString->szLboxString, (LPTSTR)base );
LboxString::operator = ( LString );
}
delete LString;
return LboxString::szLboxString;
}
| |
|
|
|
| // *********************************************************
// 先行ゼロ文字列の作成
// 戻り値 : 無し
// *********************************************************
void LboxString::Fzero( int nData, int nLen )
{
char szFormat[20];
szFormat[0] = '%';
wsprintf( szFormat+1, "0%dd", nLen );
LboxString::Printf( szFormat, nData );
}
void LboxString::Fzero( LboxString *LString, int nLen )
{
LboxString::Fzero( LString->szLboxString, nLen );
}
void LboxString::Fzero( LPTSTR lpData, int nLen )
{
char szFormat[20];
szFormat[0] = '%';
wsprintf( szFormat+1, "0%ds", nLen );
LboxString::Printf( szFormat, lpData );
}
| |
|
|
|