Getting the initials _ C # tutorial-PHP source code
Source: Internet
Author: User
Obtain the first letter of the Chinese character in the string and obtain the first letter of the Chinese character in the string (modified according to http://blog.csdn.net/iwebsms/archive/2004/09/28/119851.aspx)
The code may be bloated. I hope some friends can help me correct it.
// Returns the first letter of a given string.
Private String IndexCode (String IndexTxt)
{
String _ Temp = null;
For (int I = 0; I
_ Temp = _ Temp + GetOneIndex (IndexTxt. Substring (I, 1 ));
Return _ Temp;
}
// Obtain the first letter of a single character
Private String GetOneIndex (String OneIndexTxt)
{
If (Convert. ToChar (OneIndexTxt)> = 0 & Convert. ToChar (OneIndexTxt) <256)
Return OneIndexTxt;
Else
{
Encoding gb2312 = Encoding. GetEncoding ("gb2312 ");
Byte [] unicodeBytes = Encoding. Unicode. GetBytes (OneIndexTxt );
Byte [] gb2312Bytes = Encoding. Convert (Encoding. Unicode, gb2312, unicodeBytes );
Return GetX (Convert. ToInt32 (
String. Format ("{0: D2}", Convert. ToInt16 (gb2312Bytes [0])-160)
+ String. Format ("{0: D2}", Convert. ToInt16 (gb2312Bytes [1])-160)
));
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service