C ++字符串为小写方法? [英] C++ string to lowercase method?

查看:104
本文介绍了C ++字符串为小写方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想做的是花一个月的时间输入(1月2月等)把它变成3个字符串(jan,feb,mar),然后将它们全部改成小写,因此我不会有8个if语句(Jan,JAn,JaN,JAN,jAN,jaN,jAn,jan)来设置(因此需要84个额外的if语句,12个月)

>
我尝试了各种各样的变化,但没有用。(这是我在c ++中的第一堂课,在comp编程中排名第三,所以非常新)


so如果可以的话,请说明相当简单的证据,如果没有任何帮助,我们非常感谢。谢谢。


变量名是包


字符串月;

...(额外变量和狗屎)

getline(cin,month);

...(来自用户的额外输入)

month = month.substr(0, 3);


或者,另一种解决方案是使用像java'的string.equalsIgnoreCase()


ie: if(month.equalsIgnoreCase(" jan"))

{

...

}

解决方案

http://www.thescripts.com/forum/thread445888.html


这里有问题,正如我之前所说,我是c ++的新手,在我看来它比java差10倍,所以更难做任何事情,比如他的案例小写方法,忽略方法,许多其他比较方法等,但是我的观点,这是另一个讨论的引用。


Vadim写道:[color = blue]

>嗨!

>

>我有一个STL字符串,我需要将其转换为小写字母。

>在VC 6中我使用了:

> string sInputBuffer = _strlwr((char *)sBuffer.c_str()); [/ color]


尝试这个(std C ++ - 不知道MVC):


std :: transform(sBuffer.begin(),sBuffer.end(),sBuffer.begin(),

:: tolower);


干杯,

Andre



什么是sBuffer.begin,我在哪里放入字符串我不想修改,它不是一个char数组,它是一个我正在修改的字符串。拜托,如果你提供帮助,请告诉我它应该如何帮助我,整个讨论会变成一群像女学生一样争论的人。我需要一个示例代码来查看,而不是一个通用的代码,我应该知道那些狗屎意味着什么。比如string.substr(int,int);

被授予,这对于dicipher来说很容易,请说例如:


string s1 =" abc de fgh" ;;

s1 = s1.substr(0,5); //字符串从0开始,而不是1


感谢您的帮助。


试试这个:

展开 | 选择 | Wrap | 行号


hello, what i''m wanting to do is take a month input(january february, etc) turn it to a 3 char string(jan, feb, mar) which i have, and then turn them to all lowercase, so as i don''t haev to have 8 if statements(Jan, JAn, JaN, JAN, jAN, jaN, jAn, jan) to set up(therefore makeing 84 extra ifstatements, 12 months)

I''ve tried all sorts of variations, to no avail.(this is my first class in c++, 3rd in comp programing, so very new)

so please make the explanation fairly dumby proof if you can, if not any help is greatly appreciated. thank you.

the variable name is package

string month;
...(extra variables and shit)
getline(cin, month);
...(extra input from user)
month = month.substr(0, 3);

or, another solution to this would be to use something like java''s string.equalsIgnoreCase()

ie: if(month.equalsIgnoreCase("jan"))
{
...
}

解决方案

http://www.thescripts.com/forum/thread445888.html


here''s the problem, as i''ve said before, i''m new to c++, in my opinion its 10 times worse than java, its so much harder to do anything, like int his case lowercase methods, ignorecase methods, many other comparison methods and such, but heres my point, this is a quote from another discussion.

Vadim wrote:[color=blue]
> Hi!
>
> I have a STL string, which I need to convert to low case.
> In VC 6 I used:
> string sInputBuffer = _strlwr((char*)sBuffer.c_str());[/color]

Try this maybe (std C++ - don''t know about MVC):

std::transform( sBuffer.begin(), sBuffer.end(), sBuffer.begin(),
::tolower );

Cheers,
Andre

what''s sBuffer.begin, where do i put in the string that i wan''t to modify, its not a char array, its a string that i''m modifying. please, if you offer help, tell me how its supposed to help me, that whole discussion turns into a bunch of ppl arguing like schoolgirls. I need an example code to look at, not a generic one where i''m supposed to know what all that shit means. like string.substr(int, int);
granted, that is an easy one to dicipher, please say for example:

string s1 = "abc de fgh";
s1 = s1.substr(0, 5); //strings start at 0, not 1

thanks for help.


Try this:

Expand|Select|Wrap|Line Numbers


这篇关于C ++字符串为小写方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆