解决方案 »

  1.   

    http://www.codeproject.com/Articles/51488/Implementing-Word-Wrap-in-C
      

  2.   

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