比如我有一段话
    ******,******!******!******.
中间有一个","2个"!"最后是一个句号。
我现在要判断当一行的字符长度大于21时自动换行那样就变成这样:
    ******,******!******!**
    ****.
问题,我怎么判断离第22个字符最近的一个标点后面的字符都要换到下一行
变成这样:
    ******,******!******!
    ******.
就是在一行中不要有破句
当然用户在离第22个字符最近的标点我是不知道的,也不知道是中文输入法下的标点还是英文输入法下的标点,是全角的还是半角的我都不知道
有没有什么办法可以判断呢???

解决方案 »

  1.   

    用字符判断法,比如下面的方式:
    char c1=',';
    char c2=',';
    然后
    char.IsPunctuation(c1)和char.IsPunctuation(c2)都是true
      

  2.   

    用sliptchar[] temp = new char[3];
    temp[0] = ',';
    temp[1] = '!';
    string s = "你的字符串";
    string[] array = s.Split(temp);
    foreach(string ss in array)
    {
        这里连接就可以了
        连接前判断字符长度
        
    }
      

  3.   

    sorry
    char[] temp = new char[3];
    ---〉
    char[] temp = new char[2];
      

  4.   

    用slipt
    -->
    用SplitFaint
    真的是老了~~~
      

  5.   

    我不知道标点是什么啊不仅仅是!或者是,而已啊而且中英文输入状态下的标点都不一样的难道要我把所有常规的标点都写在tmp[]里???
      

  6.   

    不是都下班了吧
    Who can help me ... 
      waiting~~~
      

  7.   

    用正则:“\W” Regex s = new Regex("//W");
           或:  
    Regex regexTest  = new Regex("[,]|[!]|[.]");
       string strTest = "******,******!******!******.";
            string[] strSplit  = s.Split(df); //找出标点符号位置再处理strTest 
           
            for (int i = 0; a < strSplit.Length; i++)
            {
                //处理分割字符串;
             }
              //根据要求组合字符串
      

  8.   

    用正则:“\W” Regex s = new Regex("//W");
           或:  
    Regex regexTest  = new Regex("[,]|[!]|[.]");
       string strTest = "******,******!******!******.";
            string[] strSplit  = s.Split(df); //找出标点符号位置再处理strTest 
           
            for (int i = 0; a < strSplit.Length; i++)
            {
                //处理分割字符串;
             }
              //根据要求组合字符串
      

  9.   

    用split函数分割所有的单词
    计算需要换行的单词
    在那个位置插入\n
      

  10.   

    Regex regexTest  = new Regex("[,]|[!]|[.]");
       string strTest = "******,******!******!******.";
            string[] strSplit  = s.Split(df); //找出标点符号位置再处理strTest 
           
            for (int i = 0; a < strSplit.Length; i++)
            {
                //处理分割字符串;
             }
      

  11.   

    用正则:“\W” Regex s = new Regex("//W");
    所有标点 多去看看正则吧