ios 如何将 NSString 中的所有字母大写

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18571215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:56:28  来源:igfitidea点击:

How to capitalize all letters in an NSString

iphoneiosobjective-cuppercase

提问by user2588945

I'm trying to capitalize all letters in a NSStringfor a table cell label.

我正在尝试将NSString表格单元格标签中的所有字母大写。

here's my code:

这是我的代码:

  // cell title and subtitle
cell.nameLabel.text = listingNode.title;
[cell.nameLabel.text uppercaseString];

It doesn't seem to have any effect at all.

它似乎根本没有任何影响。

thanks for the help.

谢谢您的帮助。

回答by Amar

The method uppercaseStringreturns an uppercased representation of the receiver. Which means you need to collect the returned string and apply that to the label as text.

该方法uppercaseString返回接收者的大写表示。这意味着您需要收集返回的字符串并将其作为文本应用于标签。

Try this,

尝试这个,

NSString *uppercase = [cell.nameLabel.text uppercaseString];
cell.nameLabel.text =  uppercase;

Hope that helps!

希望有帮助!

回答by Jitendra

NSString * str=@"jit";

NSLog(@"%@",[str uppercaseString]);


cell.nameLabel.text=[str uppercaseString];

try this code....

试试这个代码....

回答by Agent Chocks.

you need to just convert your string to uppercase

你只需要将你的字符串转换为大写

cell.nameLabel.text=[String_name uppercaseString];

回答by Emon

What do you think about that.

你怎么看。

cell.nameLabel.text = [listingNode.title uppercaseString];

回答by likeToCode

uppercaseString returns a value - NSString that contains the result of the operation.

uppercaseString 返回一个值 - NSString 包含操作的结果。

cell.nameLabel.text = [listingNode.title uppercaseString];