按位截取字符以及绑定xml内容到repeater上
# region 方法:string TransString(string, int)按字符串的实际长度截取定长字符串
public static string TransString(string Str,int Length)
{
int i = 0, j = 0;
foreach (char Char in Str)
{
if ((int)Char > 127)
i += 2;
else
i ++;
if (i > Length)
{
Str = Str.Substring(0, j) + "";
break;
}
j ++;
}
return Str;
}
# endregion
public static string TransString(string Str,int Length)
{
int i = 0, j = 0;
foreach (char Char in Str)
{
if ((int)Char > 127)
i += 2;
else
i ++;
if (i > Length)
{
Str = Str.Substring(0, j) + "";
break;
}
j ++;
}
return Str;
}
# endregion
按位截取字符,会有半个位留下的情况
string GetSubString(string origStr,int endIndex){
byte[] bytes=System.Text.Encoding.GetEncoding("gb2312").GetBytes(origStr);
if(endIndex>=bytes.Length)
return origStr;
byte[] subBytes=new byte[endIndex];
Array.Copy(bytes,0,subBytes,0,endIndex);
return System.Text.Encoding.GetEncoding("gb2312").GetString(subBytes);
}
byte[] bytes=System.Text.Encoding.GetEncoding("gb2312").GetBytes(origStr);
if(endIndex>=bytes.Length)
return origStr;
byte[] subBytes=new byte[endIndex];
Array.Copy(bytes,0,subBytes,0,endIndex);
return System.Text.Encoding.GetEncoding("gb2312").GetString(subBytes);
}
绑定xml的内容和属性
http://weblogs.asp.net/sonukapoor/archive/2004/05/10/129215.aspx