汉字转拼音缩写的函数以及其他函数

简介:

ExpandedBlockStart.gif /// <summary>
InBlock.gif        
/// 清空指定页面上所有的控件内容,包括TextBox,CheckBox,CheckBoxList,RadioButton,RadioButtonList。但是不清
InBlock.gif        
/// 除如ListBox,DropDownList,因为这样的控件值对当前页面来说还可以用,一般这些控件里都是保存的字典数据。
InBlock.gif        
/// Author:Kevin
InBlock.gif        
/// 日期:2004-12-02
InBlock.gif        
/// </summary>
ExpandedBlockEnd.gif        
/// <param name="page"> 指定的页面</param> 

None.gif          public   static   void  ClearAllContent(System.Web.UI.Control page)
ExpandedBlockStart.gif        
{
InBlock.gif            
int nPageControls = page.Controls.Count;
InBlock.gif            
for (int i = 0; i < nPageControls; i++)
ExpandedSubBlockStart.gif            
{
InBlock.gif                
foreach (System.Web.UI.Control control in page.Controls[i].Controls)
ExpandedSubBlockStart.gif                
{
InBlock.gif                    
if (control.HasControls())
ExpandedSubBlockStart.gif                    
{
InBlock.gif                        ClearAllContent(control); 
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gif                    

InBlock.gif                        
if (control is TextBox)
InBlock.gif                            (control 
as TextBox).Text = "";
InBlock.gif
InBlock.gif                        
if (control is CheckBox)
InBlock.gif                            (control 
as CheckBox).Checked = false;
InBlock.gif
InBlock.gif                        
if (control is RadioButtonList)
InBlock.gif                            (control 
as RadioButtonList).SelectedIndex = -1;
InBlock.gif
InBlock.gif                        
if (control is RadioButton)
InBlock.gif                            (control 
as RadioButton).Checked = false;
InBlock.gif
InBlock.gif                        
if (control is CheckBoxList)
ExpandedSubBlockStart.gif                        
{
InBlock.gif                            
foreach (ListItem item in (control as CheckBoxList).Items)
ExpandedSubBlockStart.gif                            
{
InBlock.gif                                item.Selected 
= false;
ExpandedSubBlockEnd.gif                            }

ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }
//if..else
ExpandedSubBlockEnd.gif
                }
//foreach
ExpandedSubBlockEnd.gif
            }
//for
ExpandedBlockEnd.gif
        }
ExpandedBlockStart.gif /// <summary>
InBlock.gif        
/// 汉字转拼音缩写
InBlock.gif        
/// Code By MuseStudio@hotmail.com
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="str">要转换的汉字字符串</param>
ExpandedBlockEnd.gif        
/// <returns>拼音缩写</returns>

None.gif          public   string  GetPYString( string  str)
ExpandedBlockStart.gif        
{
InBlock.gif            
string tempStr = "";
InBlock.gif            
foreach(char c in str)
ExpandedSubBlockStart.gif            
{
InBlock.gif                
if((int)c >= 33 && (int)c <=126)
ExpandedSubBlockStart.gif                
{//字母和符号原样保留
InBlock.gif
                    tempStr += c.ToString();
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gif                
{//累加拼音声母
InBlock.gif
                    tempStr += GetPYChar(c.ToString());
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return tempStr;
ExpandedBlockEnd.gif        }

None.gif
ExpandedBlockStart.gif        
/// <summary>
InBlock.gif        
/// 取单个字符的拼音声母
InBlock.gif        
/// Code By MuseStudio@hotmail.com
InBlock.gif        
/// 2004-11-30
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="c">要转换的单个汉字</param>
ExpandedBlockEnd.gif        
/// <returns>拼音声母</returns>

None.gif          public   string  GetPYChar( string  c)
ExpandedBlockStart.gif        
{
InBlock.gif            
byte[] array = new byte[2];
InBlock.gif            array 
= System.Text.Encoding.Default.GetBytes(c);
InBlock.gif            
int i = (short)(array[0- '\0'* 256 + ((short)(array[1- '\0'));
InBlock.gif
InBlock.gif            
if ( i < 0xB0A1return "*";
InBlock.gif            
if ( i < 0xB0C5return "a";
InBlock.gif            
if ( i < 0xB2C1return "b";
InBlock.gif            
if ( i < 0xB4EEreturn "c";
InBlock.gif            
if ( i < 0xB6EAreturn "d";
InBlock.gif            
if ( i < 0xB7A2return "e";
InBlock.gif            
if ( i < 0xB8C1return "f";
InBlock.gif            
if ( i < 0xB9FEreturn "g";
InBlock.gif            
if ( i < 0xBBF7return "h";
InBlock.gif            
if ( i < 0xBFA6return "g";
InBlock.gif            
if ( i < 0xC0ACreturn "k";
InBlock.gif            
if ( i < 0xC2E8return "l";
InBlock.gif            
if ( i < 0xC4C3return "m";
InBlock.gif            
if ( i < 0xC5B6return "n";
InBlock.gif            
if ( i < 0xC5BEreturn "o";
InBlock.gif            
if ( i < 0xC6DAreturn "p";
InBlock.gif            
if ( i < 0xC8BBreturn "q";
InBlock.gif            
if ( i < 0xC8F6return "r";
InBlock.gif            
if ( i < 0xCBFAreturn "s";
InBlock.gif            
if ( i < 0xCDDAreturn "t";
InBlock.gif            
if ( i < 0xCEF4return "w";
InBlock.gif            
if ( i < 0xD1B9return "x";
InBlock.gif            
if ( i < 0xD4D1return "y";
InBlock.gif            
if ( i < 0xD7FAreturn "z";
InBlock.gif
InBlock.gif            
return "*";
ExpandedBlockEnd.gif        }
None.gif // 作用:把ListBox中的全部内容转换成一个字符串,各个字段间用,分隔
None.gif  
//
None.gif  
// 参数:Lists,需要转换的ListBox.items
None.gif  
//
None.gif  
// 返回值:转换好的字符串
None.gif  
//
None.gif
   public   string  ListToString(ListItemCollection Lists)
ExpandedBlockStart.gif  
{
InBlock.gif   
string result="";
InBlock.gif   
for(int i=0;i<Lists.Count;i++)
ExpandedSubBlockStart.gif   
{
InBlock.gif    
if (i==0)
ExpandedSubBlockStart.gif    
{
InBlock.gif     result
=Lists[i].Text;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gif    
{
InBlock.gif     result
=result+","+Lists[i].Text;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
return result;
ExpandedBlockEnd.gif  }
 
None.gif
None.gif  
//
None.gif  
// 作用:把string中的全部内容转换成ListItemCollection从而绑定到Listbox
None.gif  
//
None.gif  
// 参数:str,需要转换的字符串
None.gif  
//
None.gif  
// 返回值:转换好的ListItemCollection
None.gif  
//
None.gif
   public  ListItemCollection StringToList( string  str)
ExpandedBlockStart.gif  
{
InBlock.gif   ListItemCollection lists
=new ListItemCollection();
InBlock.gif   
if(str=="")                                        //字符串为空
ExpandedSubBlockStart.gif
   {
InBlock.gif    errPosition
="ListItemCollection";
InBlock.gif    errMsg
="字符串为空";
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if(str.IndexOf(",")==0)                        //首位为","
ExpandedSubBlockStart.gif
   {
InBlock.gif    errPosition
="ListItemCollection";
InBlock.gif    errMsg
="首位为,";
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if(str.Substring(str.Length-1,1)==",")        //尾位为","
ExpandedSubBlockStart.gif
   {
InBlock.gif    errPosition
="ListItemCollection";
InBlock.gif    errMsg
="尾位为,";
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else
ExpandedSubBlockStart.gif   
{
InBlock.gif    
while (str.IndexOf(",")>0)
ExpandedSubBlockStart.gif    
{
InBlock.gif     
int position=str.IndexOf(",") ;
InBlock.gif     lists.Add(str.Substring(
0,position));
InBlock.gif     str
=str.Remove(0,position+1);
ExpandedSubBlockEnd.gif    }

InBlock.gif    lists.Add(str);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
return lists;
ExpandedBlockEnd.gif  }

None.gif
None.gif  
//
None.gif  
// 作用:把源ListBox中的选中数据移动到目标ListBox
None.gif  
//
None.gif  
// 参数:FromLists,源ListBox
None.gif  
//
None.gif
   public   static   void  MoveListBoxSelectedItem
None.gif   (ListItemCollection FromLists,ListItemCollection ToLists)
ExpandedBlockStart.gif  
{
InBlock.gif   
for(int i=FromLists.Count-1;i>=0;i--)
ExpandedSubBlockStart.gif   
{
InBlock.gif    
if (FromLists[i].Selected)
ExpandedSubBlockStart.gif    
{
InBlock.gif     FromLists[i].Selected
=false;
InBlock.gif     ToLists.Add(FromLists[i]);
InBlock.gif     FromLists.Remove(FromLists[i]);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif  }

None.gif
None.gif  
//
None.gif  
// 作用:把源ListBox中的全部数据移动到目标ListBox
None.gif  
//
None.gif  
// 参数:FromLists,源ListBox
None.gif  
//
None.gif
   public   static   void  MoveListBoxAllItem
None.gif   (ListItemCollection FromLists,ListItemCollection ToLists)
ExpandedBlockStart.gif  
{
InBlock.gif   
for(int i=FromLists.Count-1;i>=0;i--)
ExpandedSubBlockStart.gif   
{
InBlock.gif    FromLists[i].Selected
=false;
InBlock.gif    ToLists.Add(FromLists[i]);
InBlock.gif    FromLists.Remove(FromLists[i]);
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif  }

None.gif
None.gif  
//
None.gif  
// 作用:输入年月返回月份的天数的集合
None.gif  
//
None.gif  
// 参数:YYYY年,MM月
None.gif  
//
None.gif  
// 返回值:本月的天数的ArrayList
None.gif  
//
None.gif
   public   static  ArrayList GetDaysInMonth( int  YYYY, int  MM)
ExpandedBlockStart.gif  
{
InBlock.gif   
int day=DateTime.DaysInMonth(YYYY,MM);
InBlock.gif   ArrayList days
=new ArrayList();
InBlock.gif   
for (int i=1;i<=day;i++)
ExpandedSubBlockStart.gif   
{
InBlock.gif    days.Add(i);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
return days;
ExpandedBlockEnd.gif  }

None.gif
None.gif
None.gif  
//
None.gif  
// 作用:输入选中天数的集合,返回其中的最小和最大的天数
None.gif  
//
None.gif  
// 参数:dates,把Calendar.SelectedDates传入即可
None.gif  
//
None.gif  
// 返回值:两个数值的ArrayList,第一个为最小天数,第二个为最大天数
None.gif  
//
None.gif
   public   static  ArrayList GetMinMaxDate(SelectedDatesCollection dates)
ExpandedBlockStart.gif  
{
InBlock.gif   ArrayList Result
=new ArrayList();
InBlock.gif   DateTime min
=new DateTime();
InBlock.gif   DateTime max
=new DateTime();
InBlock.gif   
for(int i=0;i<dates.Count;i++)
ExpandedSubBlockStart.gif   
{
InBlock.gif    
if (i>0)
ExpandedSubBlockStart.gif    
{
InBlock.gif     
if(dates[i]<min)
ExpandedSubBlockStart.gif     
{
InBlock.gif      min
=dates[i];
ExpandedSubBlockEnd.gif     }

InBlock.gif     
if(dates[i]>max)
ExpandedSubBlockStart.gif     
{
InBlock.gif      max
=dates[i];
ExpandedSubBlockEnd.gif     }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gif    
{
InBlock.gif     min
=dates[i];
InBlock.gif     max
=dates[i];
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   Result.Add(min);
InBlock.gif   Result.Add(max);
InBlock.gif   
return Result;
ExpandedBlockEnd.gif  }

None.gif
None.gif调用函数是碰到ListItemCollection 使用ListBox.Items做参数
None.gif



本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/12/253058.html,如需转载请自行联系原作者
相关文章
|
2月前
|
JavaScript
JS自动生成速记符、拼音简写/拼音的声母(例如:“你挚爱的强哥”转换为“NZADQG”)。提取首字母,返回大写形式;提取拼音, 返回首字母大写形式(全拼)。
JS自动生成速记符、拼音简写/拼音的声母(例如:“你挚爱的强哥”转换为“NZADQG”)。提取首字母,返回大写形式;提取拼音, 返回首字母大写形式(全拼)。
|
存储 编解码 索引
[oeasy]python0131_[趣味拓展]各种符号_汉语拼音符号_中文全角英文字母_中文全角标点
[oeasy]python0131_[趣味拓展]各种符号_汉语拼音符号_中文全角英文字母_中文全角标点
113 0
[oeasy]python0131_[趣味拓展]各种符号_汉语拼音符号_中文全角英文字母_中文全角标点
带声调的拼音字符比较特殊
带声调的拼音字符比较特殊
110 0
C语言常用转换控制符缩写(%g是哪个单词缩写)
C语言常用转换控制符缩写(%g是哪个单词缩写)
|
数据库
轻松解决汉字和拼音转换问题!!
轻松解决汉字和拼音转换问题!!
161 0
|
IDE 程序员 开发工具
什么,你还在用拼音命名法?
什么,你还在用拼音命名法?
148 0
什么,你还在用拼音命名法?
|
C#
C# 设置textedit只能输入英文数字下划线,并且只能以英文开头(正则表达式)
this.textEdit1.Properties.Mask.EditMask = @"[a-zA-z][a-zA-Z0-9_]*";
1694 0
|
机器学习/深度学习 移动开发 Shell