C# 所有单词首字母改为大写的方法
首先要添加引用Microsoft.VisualBasic,还要添加命名空间:using Microsoft.VisualBasic; 下面是代码:
代码
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic;
namespace VBWordDeal
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = ConvertToUpper(textBox1.Text.Trim());
}
/// <summary>
/// 返回所有单词首字改为大写后的结果
/// </summary>
/// <param name="str">普通字符串</param>
/// <returns>所有单词更改为首字母大写</returns>
public string ConvertToUpper(string str)
{
string S = Strings.StrConv(str, VbStrConv.ProperCase, System.Globalization.CultureInfo.CurrentCulture.LCID);
return S;
}
}
}
using System.Windows.Forms;
using Microsoft.VisualBasic;
namespace VBWordDeal
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = ConvertToUpper(textBox1.Text.Trim());
}
/// <summary>
/// 返回所有单词首字改为大写后的结果
/// </summary>
/// <param name="str">普通字符串</param>
/// <returns>所有单词更改为首字母大写</returns>
public string ConvertToUpper(string str)
{
string S = Strings.StrConv(str, VbStrConv.ProperCase, System.Globalization.CultureInfo.CurrentCulture.LCID);
return S;
}
}
}
来源:http://www.pczpg.com/a/2010/0526/9800.html