xcode 如何使 NSString 中的所有字符小写?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7296267/
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-09-14 21:52:07  来源:igfitidea点击:

How to make all characters lowercase in NSString?

objective-cxcodensstring

提问by Will Coughlin

How would I go about making all characters in an NSString lowercase?

我将如何让 NSString 中的所有字符都小写?

回答by Abizern

NSStringhas a cunningly named lowercaseStringmethod.

NSString有一个巧妙命名的lowercaseString方法。

NSString *noCaps = [yourString lowercaseString];

Edited to add

编辑添加

If you are asking how to change the actualstring to be lowercase - you can't. NSStrings are immutable. They can't be changed after they have been created. If you want to change the string in place you should use an NSMutableString like so:

如果您询问如何将实际字符串更改为小写 - 您不能。NSStrings 是不可变的。它们在创建后无法更改。如果你想改变字符串,你应该像这样使用 NSMutableString :

[aMutableString setString:[aMutableString lowercaseString]];