楼主我已经帮你实现了 需要引用一个微软提供的类库
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using Microsoft.International.Converters.PinYinConverter;
- namespace WindowsFormsApplication
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string r = textBox1.Text.Trim();
- string t = string.Empty;
- foreach (char obj in r)
- {
- try
- {
- ChineseChar chineseChar = new ChineseChar(obj);
- string c = chineseChar.Pinyins[0].ToString();
- t += (c.Substring(0, 1) + c.Substring(1, c.Length - 1).ToLower()).Substring(0, c.Length - 1);
- }
- catch
- {
- t += obj;
- }
- }
- textBox2.Text = t;
- }
- }
- }
复制代码 |
|