わびさびサンプルソース

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

アルファベットを大文字から小文字へ変換する

アルファベットを大文字から小文字へ変換します。

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



/*
	アルファベットを大文字から小文字へ変換する
*/
std::wstring WStringToLower
(
	std::wstring oString
)
{
	std::wstring::iterator ite    = oString.begin();
	std::wstring::iterator iteEnd = oString.end();

	while( ite != iteEnd ) {

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

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

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

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



/*
	アルファベットを大文字から小文字へ変換する
*/
int _tmain
(
	  int argc
	, _TCHAR* argv[]
)
{
	// 標準出力へユニコードを出力する
	setlocale( LC_ALL, "Japanese" );

	// アルファベットを大文字から小文字へ変換する
	std::wstring oResultStr = WStringToLower( L"ABCDEFGHIJKLMNOPQRSTUVWXYZ" );

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

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

実行結果

abcdefghijlkmnopqrstuvwxyz






わびさびサンプルソース

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