惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
The Last Watchdog
The Last Watchdog
Cyberwarzone
Cyberwarzone
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The Cloudflare Blog
V
V2EX
博客园_首页
博客园 - 聂微东
Vercel News
Vercel News
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
T
Tenable Blog
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
T
Troy Hunt's Blog
博客园 - 【当耐特】
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
A
About on SuperTechFans
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
Schneier on Security
Schneier on Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
D
Docker
P
Proofpoint News Feed

博客园 - 龙城1号

谈谈几十种文件传输工具、FTP工具、跨平台手机电脑互传工具 office必须知道的一些事情 软件下载网址大全 用eclipse开发java 配置ip的脚本bat详解 监控ip在线状态 部分毕业设计的论文和代码 隐藏在照片里的情书 关于系统多功能恢复盘制作 免费的ASP.net2.0免费空间 WMp和RealPlayer空间的一些命令 卡巴斯基激活码无限量获取 如何删除runauto...病毒 配置php开发环境 网刻 U盘启动盘 fckeditor转载 asp.net连接mysql 把SQL数据库部署到远程主机环境
截取字符串substring()
龙城1号 · 2007-11-18 · via 博客园 - 龙城1号

因为中文和英文所占位置不同,一个能显示5个中文的位置应该能显示10个英文,
这个字符串操作函数很好用,是CSDN里写的。

  ///   内容摘要:按字节截断字符串。  
                  ///   </summary>  
                  public   static   string   GetSubString(string   mText,int   startIndex,int   byteCount)  
                  {  
                          if(byteCount   <   1   )   return   string.Empty;  
                         
                          if(     System.Text.Encoding.Default.GetByteCount(mText)<=   byteCount)  
                          {   
                                  return   mText;  
                          }  
                          else  
                          {  
                                  if(startIndex   ==   0)  
                                  {  
                                          byte[]   txtBytes   =   System.Text.Encoding.Default.GetBytes(mText);  
                                          byte[]   newBytes   =   new   byte[byteCount];  
                                   
                                          for(int   i=0;i<byteCount;i++)   
                                                  newBytes[i]   =   txtBytes[i];  
   
                                          return   System.Text.Encoding.Default.GetString(newBytes);  
                                  }  
                                  else  
                                  {  
                                          string   tmp   =   GetSubString(mText,0,startIndex-1);  
                                          mText   =   mText.Substring(tmp.Length);   
                                          return   GetSubString(mText,0,byteCount);  
                                  }  
                          }  
                  }  
                  public   static   string   GetSubString(string   mText,int   startIndex)            
                  {  
                          return   GetSubString(mText,startIndex,System.Text.Encoding.Default.GetByteCount(mText)-startIndex+1);  
                  }

使用方法:
在数据绑定的地方输入这个,代替原来的<% Eval("text") %>
 <%# GetSubString(DataBinder.Eval(Container.DataItem,"text").ToString(),0,10)%>