将字符串转换为标题情况 [英] Converting string to title case

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

问题描述

我有一个包含的大写和小写字符的混合物,例如,一个简单的串的字符串。我想要做的就是每个单词的第一个字母转换(我可以假设词由空格分隔)为大写字母。所以,我要的结果是一个简单的字符串。有没有简单的方法来做到这一点?我不想分割字符串,并进行转换(这将是我最后的手段)。此外,可以保证字符串是英文的。

I have a string which contains a mixture of upper and lower case characters, for example "a Simple string" . What I want to do is to convert first character of each word ( I can assume that words are separated by spaces) into upper case. So I want the result as "A Simple String". Is there any easy way to do this? I don't want to split the string and do the conversion (that will be my last resort). Also, it is guaranteed that the strings are in English.

推荐答案

MSDN:<一href=\"http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx\">TextInfo.ToTitleCase

string title = "war and peace";

TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
title = textInfo.ToTitleCase(title); //War And Peace

这篇关于将字符串转换为标题情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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