目前不知道怎样输出带声调的拼音在C盘下面放的有一个码表储存的有汉字的拼音信息,但是没有声调using System;
using System.IO;
using System.Collections.Generic;
using System.Text;namespace 查询汉字的拼音
{
class Program
{ static string[,] mb; static void Main(string[] args)
{
MakeMB(@"c:\attach.txt", @"C:\pymb.txt");
ReadMB(@"C:\pymb.txt"); while (true)
{
Console.WriteLine("**************");
Console.WriteLine("查询汉字的拼音");
Console.WriteLine("1.查询");
Console.WriteLine("2.清屏");
Console.WriteLine("3.退出");
Console.WriteLine("**************");
Console.Write("请选择[1,2,3]:"); string cmd = Console.ReadLine(); switch (cmd)
{
case "1":
查询拼音();
Console.WriteLine();
break;
case "2":
Console.Clear();
break;
case "3":
return;
}
}
} static void 查询拼音()
{
Console.WriteLine("-----------------");
Console.Write("请输入待查的汉字:"); string hz = Console.ReadLine().Substring(0, 1); string[] py = hz2py(hz);
Console.Write("查询结果:"); for (int i = 0; i < py.Length; i++)
Console.Write("\t{0}.{1}", i + 1, py[i]);
Console.WriteLine();
Console.WriteLine("-----------------");
}
static string[] hz2py(string hz)
{
string py = string.Empty; for (int i = 0; i < mb.GetLength(0); i++)
{ if (mb[i, 1].Contains(hz))
py += (py == string.Empty ? mb[i, 0] : "|" + mb[i, 0]);
} return py.Split(new char[] { '|' });
}
static void ReadMB(string MBFileName)
{ mb = new string[415, 2];
StreamReader sr = new StreamReader(MBFileName, Encoding.Default);
string rline = string.Empty;
for (int i = 0; (rline = sr.ReadLine()) != null; i++)
{ string[] split = rline.Split(new char[] { '|' }); mb[i, 0] = split[0]; mb[i, 1] = split[1];
}
} static void MakeMB(string SrcFileName, string DesFlieName)
{ StreamReader sr = new StreamReader(SrcFileName, Encoding.Default); StreamWriter sw = new StreamWriter(DesFlieName, false, Encoding.Default);
for (string rline = string.Empty; (rline = sr.ReadLine()) != "[Text]"; ) ; for (string rline = string.Empty; (rline = sr.ReadLine()) != null; )
{ string[] split = rline.Split(new char[] { ' ' });
string wline = split[0] + "|"; for (int i = 1; i < split.Length; i++)
{ if (split[i].Length == 1)
wline += split[i];
}
if (wline != split[0] + "|")
sw.WriteLine(wline);
} sr.Close();
sw.Close();
}
}
}
using System.IO;
using System.Collections.Generic;
using System.Text;namespace 查询汉字的拼音
{
class Program
{ static string[,] mb; static void Main(string[] args)
{
MakeMB(@"c:\attach.txt", @"C:\pymb.txt");
ReadMB(@"C:\pymb.txt"); while (true)
{
Console.WriteLine("**************");
Console.WriteLine("查询汉字的拼音");
Console.WriteLine("1.查询");
Console.WriteLine("2.清屏");
Console.WriteLine("3.退出");
Console.WriteLine("**************");
Console.Write("请选择[1,2,3]:"); string cmd = Console.ReadLine(); switch (cmd)
{
case "1":
查询拼音();
Console.WriteLine();
break;
case "2":
Console.Clear();
break;
case "3":
return;
}
}
} static void 查询拼音()
{
Console.WriteLine("-----------------");
Console.Write("请输入待查的汉字:"); string hz = Console.ReadLine().Substring(0, 1); string[] py = hz2py(hz);
Console.Write("查询结果:"); for (int i = 0; i < py.Length; i++)
Console.Write("\t{0}.{1}", i + 1, py[i]);
Console.WriteLine();
Console.WriteLine("-----------------");
}
static string[] hz2py(string hz)
{
string py = string.Empty; for (int i = 0; i < mb.GetLength(0); i++)
{ if (mb[i, 1].Contains(hz))
py += (py == string.Empty ? mb[i, 0] : "|" + mb[i, 0]);
} return py.Split(new char[] { '|' });
}
static void ReadMB(string MBFileName)
{ mb = new string[415, 2];
StreamReader sr = new StreamReader(MBFileName, Encoding.Default);
string rline = string.Empty;
for (int i = 0; (rline = sr.ReadLine()) != null; i++)
{ string[] split = rline.Split(new char[] { '|' }); mb[i, 0] = split[0]; mb[i, 1] = split[1];
}
} static void MakeMB(string SrcFileName, string DesFlieName)
{ StreamReader sr = new StreamReader(SrcFileName, Encoding.Default); StreamWriter sw = new StreamWriter(DesFlieName, false, Encoding.Default);
for (string rline = string.Empty; (rline = sr.ReadLine()) != "[Text]"; ) ; for (string rline = string.Empty; (rline = sr.ReadLine()) != null; )
{ string[] split = rline.Split(new char[] { ' ' });
string wline = split[0] + "|"; for (int i = 1; i < split.Length; i++)
{ if (split[i].Length == 1)
wline += split[i];
}
if (wline != split[0] + "|")
sw.WriteLine(wline);
} sr.Close();
sw.Close();
}
}
}
a|阿啊呵吖嗄腌锕錒
ba|把八吧爸拔罢跋巴芭扒坝霸叭....
即 拼音+"|"+这个拼音的汉字
这个问题主要是数据库如何建立,要有数据源啊
http://www.yzzs.com/Article/ShowArticle.asp?ArticleID=2081
这里有完整的