比如string a="给字符串都加上空格";我要把这串字符显示成 “给 字 符 串 都 加 上 空 格”,怎么做 ??

解决方案 »

  1.   


                string str = "给字符串都加上空";
                List<char> listString = str.ToList();
                StringBuilder spaceStr = new StringBuilder();
                foreach (char c in listString)
                {
                    spaceStr.Append(c.ToString());
                    spaceStr.Append(" ");
                }
      

  2.   

    你显示的话可以采用css,无需在内容里面加
      

  3.   

    <span style="letter-spacing:12px">给字符串都加上空格</span>
      

  4.   

    不用CSS,我就想知道怎么读字符串进行操作!
      

  5.   


    string a="给字符串都加上空格";
    string b = System.Text.RegularExpressions.Regex.Replace(a, "(.)", "$1 ");也可以尝试这样。
      

  6.   

    string a = "给字符串都加上空格";
                Console.WriteLine(Regex.Replace(a,@"\B()\B"," "))
      

  7.   


    //linq
    void Main()
    {
    string a="给字符串都加上空格";
    a=string.Join("",(a.ToCharArray().Select(b=>b+" ")).ToArray());
    Console.WriteLine(a); //给 字 符 串 都 加 上 空 格 }
      

  8.   


    Regex.Replace(str, @"(?<=\B)(?=\B)", " ");
      

  9.   

    不需要LINQ,最基础的字符串操作即可string a = "给字符串都加上空格";
    string result = string.Join(" ", a.ToCharArray());
      

  10.   

    非要用正则的话,不要用\B,有局限性,遇到单词边界处理结果就不对了string a = "给字符串!@#都加上空格";
    string result = Regex.Replace(a, "(?s)(?<=.)(?=.)", " ");
      

  11.   

    介个public static string Join (
    string separator,
    string[] value
    )
      

  12.   

     string str = "给字符串都加上空格";
                string getStr = string.Empty;
                MatchCollection matchs = Regex.Matches(str, @"([\w])");
                foreach (Match m in matchs)
                {
                    getStr += m.Value + " ";
                }
                Console.Write(getStr);
      

  13.   


                String str = "给字符串都加上空格";
                Response.Write(String.Format("Str's length:{0}", str.Length));
                Response.Write("<br/>"+str);
                Int32 index=0;
                while (index <= str.Length)
                {
                    str = str.Insert(index, " ");
                    index += 2;
                }            Response.Write(String.Format("Str's length:{0}",str.Length));
                Response.Write("<br/>" + str);
      

  14.   

     string abc = "请把每个字后面加上个空格";
                int index = abc.Length;
                string abc1 = string.Empty;
                for (int i = 0; i < index;i++ )
                {
                   
                    abc1 += abc.Substring(i,1)+" ";
                }
               
                Response.Write(abc1);