随笔-19  评论-6  文章-5  trackbacks-0

按位截取字符以及绑定xml内容到repeater上

# region 方法:string TransString(stringint)按字符串的实际长度截取定长字符串
public static string TransString(string Str,int Length)
{
int i = 0, j = 0;
foreach (char Char in Str)
{
if ((int)Char > 127)
+= 2;
else
++;
if (i > Length)
{
Str 
= Str.Substring(0, j) + "";
break;
}

++;
}

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);

 }

 


绑定xml的内容和属性
http://weblogs.asp.net/sonukapoor/archive/2004/05/10/129215.aspx

posted on 2005-02-25 00:29 tangle 阅读(413) 评论(0) 编辑 收藏
昵称:tangle
园龄:7年9个月
粉丝:14
关注:32
<2005年2月>
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

搜索

 
 

常用链接

随笔分类

随笔档案

最新评论

阅读排行榜

评论排行榜

推荐排行榜