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

推荐订阅源

P
Proofpoint News Feed
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
月光博客
月光博客
F
Full Disclosure
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
F
Fortinet All Blogs
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Recorded Future
Recorded Future
Y
Y Combinator Blog
博客园 - 聂微东
爱范儿
爱范儿
D
DataBreaches.Net
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
SecWiki News
SecWiki News
Webroot Blog
Webroot Blog
Engineering at Meta
Engineering at Meta
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
O
OpenAI News
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic

博客园 - skylai

mvc3 小技巧 WCF学习之旅(一)---Hello World. WCF Client configuration Jquery表单验证 Jquery的一些常用信息 二进制、SOAP的序列化及反序列化 简单的Attribute实现. 泛型之泛型约束 C#泛型之泛型委托 C#2.0泛型介绍之简单泛型类。 序列化之XML序列化(一) Vs2005的win form动态生成菜单 js操作xml 读写XML文件 js的一些杂谈 一个button同时执行多个有返回值的函数的解决方法(return false; or return true;) DataGrid里应用radio单选按钮 限制字符输入(ASCII 码) 前两天刚看书看到的,来这里跟大家分享一下有关C#处理指令的问题
强制字符换行CSS版和C#版
skylai · 2006-08-11 · via 博客园 - skylai

强制字符换行。
style="word-break:break-all;word-wrap:break-word";
C#版:


        
//oldString:要换行的字符串,width:每行的字符宽度(字符个数),tolerance:最长的单词长度,以免单词被从中截断
        
//spanWidth,每一行的宽度
        public static String GetMutilLineString(String oldString, Int32 width, Int32 tolerance, Int32 spanWidth)
        
{
            
if (oldString == null)
            
{
                
return null;
            }

            
if (oldString.Trim() == String.Empty)
            
{
                
return String.Empty;
            }

            
if (width <= 1)
            
{
                width 
= 150;
            }

            Int32 iIndex 
= 0;
            Int32 iFindLen 
= 0;
            String strUnit 
= String.Empty;
            String strFind 
= String.Empty;
            String strReturn 
= String.Empty;
            String strTemp 
= String.Empty;
            Int32 iTolerance 
= (tolerance > 0? tolerance : 8;
            Int32 iTempIndex 
= -1;
            
while (oldString.Length > width + iTolerance)
            
{
                iFindLen 
= 2 * iTolerance;
                strFind 
= oldString.Substring(width - iTolerance, iFindLen);

                iIndex 
= strFind.LastIndexOf(",", iFindLen - 1);
                
if (iIndex == -1)
                
{
                    iIndex 
= strFind.LastIndexOf("'", iFindLen - 1);
                }

                
if (iIndex == -1)
                
{
                    iIndex 
= strFind.LastIndexOf(";", iFindLen - 1);
                }

                
if (iIndex == -1)
                
{
                    iIndex 
= strFind.LastIndexOf(".", iFindLen - 1);
                }

                
if (iIndex == -1)
                
{
                    iIndex 
= strFind.LastIndexOf(" ", iFindLen - 1);
                }

                
if (iIndex == -1)
                
{
                    iIndex 
= strFind.LastIndexOf("_", iFindLen - 1);
                }

                
if (iIndex == -1)
                
{
                    iIndex 
= strFind.LastIndexOf("-", iFindLen - 1);
                }

                
if (iIndex == -1)
                
{
                    strUnit 
= oldString.Substring(0, width);
                    oldString 
= oldString.Remove(0, width);
                }

                
else
                
{
                    strUnit 
= oldString.Substring(0, width - iTolerance + iIndex + 1);
                    oldString 
= oldString.Remove(0, width - iTolerance + iIndex + 1);
                }

                
while (strUnit.IndexOf("\r\n"> -1)
                
{
                    iTempIndex 
= strUnit.IndexOf("\r\n");
                    strTemp 
= strUnit.Substring(0, iTempIndex);
                    strReturn 
+= String.Format("<tr width={0} style='word-wrap:break-word'><td>{1}</td></tr>", spanWidth, strTemp);
                    strUnit 
= strUnit.Remove(0, iTempIndex + 2);
                }


                strReturn 
+= String.Format("<tr width={0} style='word-wrap:break-word'><td>{1}</td></tr>", spanWidth, strUnit);
            }

            
while (oldString.IndexOf("\r\n"> -1)
            
{
                iTempIndex 
= oldString.IndexOf("\r\n");
                strTemp 
= oldString.Substring(0, iTempIndex);
                strReturn 
+= String.Format("<tr width={0} style='word-wrap:break-word'><td>{1}</td></tr>", spanWidth, strTemp);
                oldString 
= oldString.Remove(0, iTempIndex + 2);
            }

            strReturn 
+= String.Format("<tr width={0} style='word-wrap:break-word'><td>{1}</td></tr>", spanWidth, oldString);

            strReturn 
= String.Format("<table>{0}</table>",strReturn);

            
return strReturn;
        }