求c#大神帮忙写一个c#通用函数,将传入的字符串按一定格式输出 c#函数格式化输出 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.codeproject.com/Articles/51488/Implementing-Word-Wrap-in-C class Program { static void Main(string[] args) { String str = "今后,江苏联络处在公安部的授权范围内开展工作,接受国际刑警组织中国国家中心局的业务指导,负责20%~30%国际刑警组织框架内的联络工作,统筹全省公安机关22.543%~60%涉外刑事案件的协调组织。", str2 = ""; MatchCollection s = Regex.Matches(str, @"(?:[0-9]+.)?([0-9]+%~[0-9]+%)"); Dictionary<int, int> Dict = new Dictionary<int,int>(); foreach (Match nextMatch in s) { Dict.Add(nextMatch.Index, nextMatch.Length); } int lineLen = 30, i = 0, Leng, lineR = 0; while (str.Length>i) { if ((Dict.TryGetValue(i,out Leng))&&(lineR + Leng > lineLen)) { str2 += "\n" + str[i]; i++; lineR = 1; continue; } if ((str[i] >= 0x4E00 && str[i] <= 0x9FBB) || (@"[,。;?~!:‘“”’【】()]".Contains(str[i]))) lineR += 2; else lineR++; str2 += str[i]; i++; if (lineR >= lineLen) { str2 += '\n'; lineR = 0; } } Console.Write(str2); } } avphoenixi大神现在我连数据都取不出来了啊 关于SelectedIndices属性和索引器语法 [Help]智能手机一般用来做些方面的系统开发? 如何用C#实现将屏幕当做画布做手写识别 请教一个计算日期方面的问题,50分! 网络编程高手请进 C#引用VS2005编译的dll出错 请问在那里有<<C#入门经典>>这本书的电子版下载啊? 初级的数据库问题,但是没有发现一本书提到,哪位大哥帮一下忙? 大家能不能 给几个 简单的 c#例子 让我看看啊 VS2008 如何调用.net 4.0的dll? 访问webservice
{
static void Main(string[] args)
{
String str = "今后,江苏联络处在公安部的授权范围内开展工作,接受国际刑警组织中国国家中心局的业务指导,负责20%~30%国际刑警组织框架内的联络工作,统筹全省公安机关22.543%~60%涉外刑事案件的协调组织。",
str2 = "";
MatchCollection s = Regex.Matches(str, @"(?:[0-9]+.)?([0-9]+%~[0-9]+%)");
Dictionary<int, int> Dict = new Dictionary<int,int>();
foreach (Match nextMatch in s)
{
Dict.Add(nextMatch.Index, nextMatch.Length);
}
int lineLen = 30,
i = 0,
Leng,
lineR = 0;
while (str.Length>i)
{
if ((Dict.TryGetValue(i,out Leng))&&(lineR + Leng > lineLen))
{
str2 += "\n" + str[i]; i++;
lineR = 1;
continue;
}
if ((str[i] >= 0x4E00 && str[i] <= 0x9FBB) ||
(@"[,。;?~!:‘“”’【】()]".Contains(str[i]))) lineR += 2;
else lineR++;
str2 += str[i]; i++;
if (lineR >= lineLen)
{
str2 += '\n';
lineR = 0;
}
}
Console.Write(str2);
}
}