文字列クラス


  Replace



  
// *********************************************************
// 指定文字列置き換え
// 戻り値 : 無し
// *********************************************************
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;
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ