xtrimtest.cpp

来自「把文字串頭去除空白或把文字串尾去除空白.」· C++ 代码 · 共 62 行

CPP
62
字号
// XTrimTest.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <tchar.h>
#include "XTrim.h"


int _tmain(int /*argc*/, TCHAR ** /*argv*/)
{
	TCHAR * cp = NULL;
	TCHAR string1[100];
	TCHAR string2[100];

	///////////////////////////////////////////////////////////////////////////
	// test _tcsltrim
	_tprintf(_T("\nTesting _tcsltrim...  "));

	_tcscpy(string1, _T("   \tThis is a test"));
	_tcscpy(string2, _T("This is a test"));

	cp = _tcsltrim(string1);

	if (cp)
	{
		if (_tcscmp(string2, cp) == 0)
			_tprintf(_T("_tcsltrim OK\n"));
		else
			_tprintf(_T("ERROR: _tcsltrim failed\n"));
	}
	else
	{
		_tprintf(_T("ERROR: _tcsltrim returned NULL\n"));
	}

	///////////////////////////////////////////////////////////////////////////
	// test _tcsrtrim
	_tprintf(_T("\n\nTesting _tcsrtrim...  "));

	_tcscpy(string1, _T("This is a test\t   "));
	_tcscpy(string2, _T("This is a test"));

	cp = _tcsrtrim(string1);

	if (cp)
	{
		if (_tcscmp(string2, cp) == 0)
			_tprintf(_T("_tcsrtrim OK\n"));
		else
			_tprintf(_T("ERROR: _tcsrtrim failed\n"));
	}
	else
	{
		_tprintf(_T("ERROR: _tcsrtrim returned NULL\n"));
	}

	_tprintf(_T("\n\nPress any key to continue"));
	_gettchar();
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?