C++ tolower on special characters such as ü

前端 未结 3 462
耶瑟儿~
耶瑟儿~ 2020-12-19 13:25

I have trouble transforming a string to lowercase with the tolower() function in C++. With normal strings, it works as expected, however special characters are not converted

3条回答
  •  长情又很酷
    2020-12-19 14:05

    use ASCII

    string NotLowerCase = "Grüßen";
    string LowerCase = "";
    for (unsigned int i = 0; i < NotLowerCase.length(); i++) {
        if(NotLowerCase[i]<65||NotLowerCase[i]>122)
        {
            LowerCase+='?';
        }
        else
            LowerCase += tolower(NotLowerCase[i]);
    }
    

提交回复
热议问题