c# - .Net 中的内置字符大小写功能

标签 c# .net string

.Net 中是否有任何内置函数允许将字符串大写或处理适当的大小写?我知道 Microsoft.VB 命名空间中的某处有一些内容,但我想尽可能避免使用这些内容。

我知道 string.ToUpper 和 string.ToLower() 等函数,但它会影响整个字符串。我正在寻找这样的东西:

var myString = "micah";
myString = myString.Format(FormattingOptions.Capitalize) //Micah

最佳答案

只是将另一个选项加入组合。这会将给定字符串中的每个单词大写:

public static string ToTitleCase(string inputString)

{

   System.Globalization.CultureInfo cultureInfo =
   System.Threading.Thread.CurrentThread.CurrentCulture;
   System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
   return textInfo.ToTitleCase(inputString.ToLower());

}

关于c# - .Net 中的内置字符大小写功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/425908/

相关文章:

c# - 如何在 C# 中创建类 A,其中 A 只能由 B、C、D 继承?

.net - FormView.FindControl() 在 DataBind() 之前返回 null

c# - 信号量会阻止指令重新排序吗?

ruby - 如何从字符串中提取字符串?

c# - 使用 KendoUI Grid,如何将可选图像或图标添加到行模板中?

c# - List.Contains 奇怪的行为

c# - 如何使用虚方法显式实现接口(interface)?

java - 字符串长度从 Javascript 到 Java 代码不同

string - 从字符串中提取 X 和 Y 坐标

c# - 为 UserControl 填充模型的正确方法是什么?