请参考:
http://dotnet.mblogger.cn/qiuji/posts/1869.aspx

解决方案 »

  1.   

    string tt= "abcdefg";
    tt = tt.Substring(0,4);
      

  2.   

    楼主,visual studio 的SDK文档里,搜索字符串各种字符串操作都有了.还有,你在string型变量后加一点“.”,它的属性,方法全来了,自己看看,比在这里问问题快多了.
      

  3.   

    呵呵。最近在学正则,来个正则的吧:
    string newString="",rStr = @"\S{4}";
    Regex r = new Regex(rStr);
    Match m = r.Match(str);
    newString = m.ToString();
    不知对不对,请各位大侠赐教
      

  4.   

    上楼的正则,相配应该是一个数组,参考下面的:
     Regex r = new Regex("abc"); 
        // Find a single match in the string.
        Match m = r.Match("123abc456"); 
        if (m.Success) 
        {
            // Print out the character position where a match was found. 
            // (Character position 3 in this case.)
            Console.WriteLine("Found match at position " + m.Index);
        }
      

  5.   

    private string CutString(string inputString,int len)
    {
    ASCIIEncoding ascii =  new ASCIIEncoding();
    int tempLen=0;
    string tempString="";
    byte[] s = ascii.GetBytes(inputString);
    for(int i=0;i<s.Length;i++)
    {
    if((int)s[i]==63)
    {
    tempLen+=2;
    }
    else
    {
    tempLen+=1;
    }
                    
    try
    {
    tempString+=inputString.Substring(i,1);
    }
    catch
    {
    break;
    } if(tempLen>len)
    break;
    }
    //如果截过则加上半个省略号
    byte[] mybyte=System.Text.Encoding.Default.GetBytes(inputString);
    if(mybyte.Length>len)
    tempString+="…"; return tempString;
    }其他地方这样调用
    CutString(dr["标题"].ToString(),20)