怎么样asp.net汉字转拼音和获取汉字首字母的代码
以下是我的源代码<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Book_View.aspx.cs" Inherits="KeLin.WebSite.download.Book_View" %><%@ Import namespace="KeLin.ClassManager.Tool" %><%
Response.Write(WapTool.showTop(bookVo.book_title, wmlVo));//显示头
if (ver == "1")
{
strhtml.Append("<p align=\"" + classVo.position + "\">");
//显示广告
if (adVo.threeShowTop != "")
{
strhtml.Append(adVo.threeShowTop + "<br/>");
}
strhtml.Append("【书名】" + bookVo.book_title + "<br/>");
string strImg = ""; //图片链接
StringBuilder strDown = new StringBuilder(); //文件下载
for (int i = 0; (filelist != null && i < filelist.Count); i++)
{
if (".gif|.jpg|.jpeg|.png|.bmp|".IndexOf(filelist[i].book_ext.ToLower()) >= 0)
{
if (filelist[i].book_file.StartsWith("/") || filelist[i].book_file.ToLower().StartsWith("http://"))
{
strImg = strImg + ("<img src=\"" + filelist[i].book_file + "\" alt=\"load...\"/><br/>");
}
else
{
strImg = strImg + ("<a href=\"" + this.http_start + "download/picDIY.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&id=" + this.id + "&path=" + HttpUtility.UrlEncode(@"download\" + filelist[i].book_file) + "&sid=" + this.sid + "\"><img src=\"" + this.http_start + "download/" + filelist[i].book_file + "\" alt=\"load...\"/></a><br/>");
}
if (filelist[i].book_content != "")
{
strImg = strImg + (filelist[i].book_content + "<br/>");
}
ImgList.Add(strImg);
strImg = "";
}
else
{
strDown.Append("");
strDown.Append("<a href=\"" + this.http_start + "download/download.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&book_id=" + this.id + "&sid=" + this.sid + "&id=" + filelist[i].ID + "&RndPath=" + siteVo.SaveUpFilesPath + "&n=" + HttpUtility.UrlEncode(filelist[i].book_title) + "." + filelist[i].book_ext.Replace(".", "") + "\">" + filelist[i].book_ext.Replace(".", "") + "格式(大小" + filelist[i].book_size + ")</a><br/>");
strDown.Append(filelist[i].book_content + "");
}
}
//对ImgList进行分页
if (pview == 0)
{
for (int i = 0; i < ImgList.Count; i++)
{
strhtml.Append(ImgList[i]);
}
}
else if (ImgList.Count > 1)
{
if (pview > ImgList.Count || pview < 1) pview = 1;
strhtml.Append(ImgList[pview - 1]);
//生成分页图链接
strhtml.Append("<a href=\"" + this.http_start + "download/book_view.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&id=" + this.id + "&pview=0&lpage=" + this.lpage + "&sid=" + sid + "\">截图</a>:");
for (int i = 1; i <= ImgList.Count; i++)
{
if (pview == i)
{
strhtml.Append(i + " ");
}
else
{
strhtml.Append("<a href=\"" + this.http_start + "download/book_view.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&id=" + this.id + "&pview=" + i + "&lpage=" + this.lpage + "&sid=" + sid + "\">" + i + "</a> ");
}
}
strhtml.Append("<br/>");
}
else if (ImgList.Count == 1)
{
strhtml.Append(ImgList[0]);
}
{
}
if (bookVo.money > 1)
{
strhtml.Append("【扣币 " + bookVo.money + "枚】");strhtml.Append("<a href=\"" + this.http_start + "download/book_se.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&page=" + this.lpage + "&sid=" + this.sid + "\">获取铜板</a><br/>");
}
strhtml.Append("【作者】<a href=\"" + this.http_start + "download/Book_List.aspx?action=search&siteid=" + this.siteid + "&classid=0&key=" + bookVo.updateInfo + "&type=title&sid=" + this.sid + "\">" + bookVo.updateInfo + "</a><br/>");
strhtml.Append("【分类】<a href=\"" + this.http_start + "download/book_list.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&page=" + this.lpage + "&sid=" + this.sid + "\">" + classVo.classname + "</a><br/>");
strhtml.Append("【阅读】<a href=\"http://ad2.easou.com:8080/j10ad/ea.jsp?channel=2&cid=bccn3506_44643_D_1&key=" + bookVo.book_title + "\">在线试读本书</a><br/>");
strhtml.Append("【更新】" + string.Format("{0:yyyy-MM-dd}", bookVo.book_date) + "<br/>");
if (bookVo.updateInfo != "")
if (content != "")
{
strhtml.Append("【简介】");
if (view != "all" && this.content.Length > 100)
{
strhtml.Append(content.Substring(0, 100) + "...");
strhtml.Append("<a href=\"" + http_start_url + "&id=" + this.id + "&vpage=2&view=all\">[更多..]</a>");
}
else
{
strhtml.Append(content);
}
strhtml.Append("<a href=\"" + this.http_start + "download/Report_add.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&page=" + this.lpage + "&id=" + this.id + "&sid=" + this.sid + "\"><br/>举报(电子书不良信息)</a>");
strhtml.Append("<a href=\"" + this.http_start + "download/book_view1.wml?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&page=" + this.lpage + "&sid=" + this.sid + "\"><br/>帮助(小说疑难杂症解决)</a>");
//显示内容列表
strhtml.Append("<br/><b>-=电子书下载地址=-</b><br/>");
}
strhtml.Append(strDown);
if (filelist == null || filelist.Count < 1)
{
if (this.myua != "" && this.myua != "0")
{
strhtml.Append("暂无适合" + mobileVo.nameCN + " " + mobileVo.Mode + " 的记录!<br/>");
}
}
if (dlist != null && filelist != null)
{
if (dlist.Count != filelist.Count)
{
strhtml.Append("<a href=\"" + this.http_start + "download/book_viewua.aspx?sp=" + this.sp + "&siteid=" + this.siteid + "&classid=" + this.classid + "&lpage=" + this.lpage + "&id=" + this.id + "&sid=" + this.sid + "\">该软件还支持其他机型</a>");
}
}
strhtml.Append("已有(" + bookVo.book_click + ")人浏览过该书<br/>");
strhtml.Append("<a href=\"" + http_start + "download/book_view.aspx?sp=" + this.sp + "&siteid=" + siteid + "&classid=" + classid + "&state=1&lpage=" + lpage + "&id=" + id + "&sid=" + sid + "\">好看顶一下!" + bookVo.ding + "</a>|<a href=\"" + http_start + "download/book_re.aspx?sp=" + this.sp + "&pageback=&getTotal=" + bookVo.book_re + "&id=" + id + "&classid=" + classid + "&siteid=" + siteid + "&sid=" + sid + "\">发表书评" + bookVo.book_re + "</a><br/> ");
strhtml.Append("----------<br/>");
//显示上一页下一页,可关闭加速性能
strhtml.Append(bll.GetPreNextTitle(ver, lang, http_start_url, siteid, classid, id, order, condition));
//显示评论
if ("1".Equals(showRe))
{
//显示最新回复
strhtml.Append("文明社会,文明评论<br/><input type=\"text\" name=\"con" + r + "tent\" value=\"\" maxlength=\"200\"/><br/>");
strhtml.Append("<anchor><go href=\"" + http_start + "download/book_re.aspx\" method=\"post\" accept-charset=\"utf-8\">");
strhtml.Append("<postfield name=\"action\" value=\"add\"/>");
strhtml.Append("<postfield name=\"id\" value=\"" + id + "\"/>");
strhtml.Append("<postfield name=\"siteid\" value=\"" + siteid + "\"/>");
strhtml.Append("<postfield name=\"lpage\" value=\"" + lpage + "\"/>");
strhtml.Append("<postfield name=\"content\" value=\"$(con" + r + "tent)\"/>");
strhtml.Append("<postfield name=\"classid\" value=\"" + classid + "\"/>");
strhtml.Append("<postfield name=\"sid\" value=\"" + sid + "\"/>");
strhtml.Append("<postfield name=\"backurl\" value=\"" + HttpUtility.UrlEncode("download/book_view.aspx?siteid=" + siteid + "&classid=" + classid + "&id=" + id) + "\"/>");
strhtml.Append("</go>发表评论</anchor><br/>");
for (int i = 0; (relistVo != null && i < relistVo.Count); i++)
{
strhtml.Append("[" + (bookVo.book_re - k) + "楼]");
if (relistVo[i].content.Length > 10)
{
strhtml.Append(relistVo[i].content.Substring(0, 9) + "...(" + string.Format("{0:MM-dd HH:mm}", relistVo[i].redate) + ")<br/>");
}
else
{
strhtml.Append(relistVo[i].content + "(" + string.Format("{0:MM-dd HH:mm}", relistVo[i].redate) + ")<br/>");
}
k = k + 1;
}
if (relistVo == null)
{
strhtml.Append("暂无评论!<br/>");
}
else
{
strhtml.Append("<a href=\"" + http_start + "download/book_re.aspx?pageback=&getTotal=" + bookVo.book_re + "&id=" + id + "&classid=" + classid + "&siteid=" + siteid + "&sid=" + sid + "\">更多评论(" + bookVo.book_re + ")</a><br/>");
}
}
--------------------编程问答-------------------- 改怎么才能转换? --------------------编程问答-------------------- 需要一个很大的集合的,【叶子函数分享五十四】汉字转拼音函数
http://blog.csdn.net/maco_wang/article/details/6290128 --------------------编程问答--------------------
//汉字转拼音缩写
/// 〈summary〉
/// 汉字转拼音缩写
/// Code By MuseStudio@hotmail.com
/// 2004-11-30
/// 〈/summary〉
/// 〈param name="str"〉要转换的汉字字符串〈/param〉
/// 〈returns〉拼音缩写〈/returns〉
public string GetPYString(string str)
{
string tempStr = "";;
foreach(char c in str)
{
if((int)c 〉= 33 && (int)c 〈=126)
{//字母和符号原样保留
tempStr += c.ToString();;
}
else
{//累加拼音声母
tempStr += GetPYChar(c.ToString());;
}
}
return tempStr;;
}
/// 〈summary〉
/// /// Code By MuseStudio@hotmail.com
/// 2004-11-30
/// 〈/summary〉
/// 〈param name="c"〉要转换的单个汉字〈/param〉
/// 〈returns〉拼音声母〈/returns〉
public string GetPYChar(string c)
{
byte[] array = new byte[2];;
array = System.Text.Encoding.Default.GetBytes(c);;
int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));;
if ( i 〈 0xB0A1) return "*";;
if ( i 〈 0xB0C5) return "a";;
if ( i 〈 0xB2C1) return "b";;
if ( i 〈 0xB4EE) return "c";;
if ( i 〈 0xB6EA) return "d";;
if ( i 〈 0xB7A2) return "e";;
if ( i 〈 0xB8C1) return "f";;
if ( i 〈 0xB9FE) return "g";;
if ( i 〈 0xBBF7) return "h";;
if ( i 〈 0xBFA6) return "g";;
if ( i 〈 0xC0AC) return "k";;
if ( i 〈 0xC2E8) return "l";;
if ( i 〈 0xC4C3) return "m";;
if ( i 〈 0xC5B6) return "n";;
if ( i 〈 0xC5BE) return "o";;
if ( i 〈 0xC6DA) return "p";;
if ( i 〈 0xC8BB) return "q";;
if ( i 〈 0xC8F6) return "r";;
if ( i 〈 0xCBFA) return "s";;
if ( i 〈 0xCDDA) return "t";;
if ( i 〈 0xCEF4) return "w";;
if ( i 〈 0xD1B9) return "x";;
if ( i 〈 0xD4D1) return "y";;
if ( i 〈 0xD7FA) return "z";;
return "*";;
}
拼音转汉字 --------------------编程问答--------------------
这个我该怎么插? --------------------编程问答-------------------- 我记得貌似有种简单的通过编码方式来进行转化的函数,应该在网上能搜到!
--------------------编程问答--------------------
直接调用就可以,返回字符串。 --------------------编程问答--------------------
你想怎么插就怎么插,
string py = this.GetPYString("姚名");
py就是"YM";
补充:.NET技术 , ASP.NET