わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。

半角数字を全角数字に変換する

半角数字を全角数字に変換する

#include <tchar.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <windows.h>



/*
	半角数字を全角数字に変換する
*/
std::wstring WStringNumberToAll
(
	std::wstring oString
)
{
	std::wstring::iterator ite    = oString.begin();
	std::wstring::iterator iteEnd = oString.end();

	while( ite != iteEnd ) {

		/*
			'0~9'なら'0~9'に変換する
		*/
		if ( ( L'0' <= *ite ) && ( L'9' >= *ite ) ) {
			*ite += ( L'0' - L'0' );
		}

		// 次の文字へ
		ite++;
	}

	// 正常終了
	return( oString );
}



/*
	半角数字を全角数字に変換する
*/
int _tmain
(
	  int argc
	, _TCHAR* argv[]
)
{
	// 標準出力へユニコードを出力する
	setlocale( LC_ALL, "Japanese" );

	// 半角数字を全角数字に変換する
	std::wstring oResultStr = WStringNumberToAll( L"0123456789" );

	// 結果を表示
	std::wcout << oResultStr.c_str() << std::endl;

	// 正常終了
	return( 0 );
}

実行結果

0123456789






わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。