공부/코테 준비하자

대소문자 변경

_mwmw 2022. 9. 9. 23:17

방법 1

ascii 코드를 활용한다.

string str = "MapleStory";
// 대문자 > 소문자
str[0] += 'a' - 'A'; // "mapleStory"
// 소문자 > 대문자
str[1] += 'A' - 'a'; // "mApleStory"

 

방법 2

toupper, tolower를 사용한다.

string str = "MapleStory";
// 무엇이든 > 소문자
str[0] = tolower(str[0]); // "mapleStory";
// 무엇이든 > 대문자
str[1] = toupper(str[1]); // "mApleStory"