如何在字符串中创建每个单词以WP7 Silverlight中的大写字母开头?

时间:2012-06-20 08:03:24

标签: string silverlight windows-phone-7

我尝试过像

这样的代码
string s = "this is example";
txt1TextBlock.Text = Thread.CurrentCulture.TextInfo.ToTitleCase(s);

但似乎WP7 Silverlight与众不同..

有没有办法做到这一点?

感谢..

2 个答案:

答案 0 :(得分:2)

尝试以下方法,

String s = "this is example";
string result = "";
string[] words = s.Split(' ');
for (int i = 0, l = words.Length; i < l; ++i)
{
     result = result + words[i][0].ToString().ToUpper() + words[i].Substring(1) + " ";
}
MessageBox.Show("Old Value: "+s+" New Value: "+result);

答案 1 :(得分:0)

因为我们在Silverlight windows phone的String类中没有Split方法..你应该使用基本字符串函数,如SubString(),Append(),Replace(),ToUpper()和ToLower().. < / p>

请参阅以下教程..

http://www.c-sharpcorner.com/UploadFile/stephenarmbrust/FunctiontoChangeaBlockofTextofTitleCase11232005231948PM/FunctiontoChangeaBlockofTextofTitleCase.aspx