如果A1=“张三”,A2=“张三三”,用string.format如何使它们输出时对齐?

解决方案 »

  1.   

    string s="My name is {0}";
    s=string.Format (s,"daniel");
    Response.Write (s);
      

  2.   

    Response.Write(String.Format("{0,-10:*}{0,-10:*}", a1, a2).Replace(" ", "&nbsp"))
      

  3.   

    Response.Write(String.Format("{0,-10:*}{0,-10:*}<br>", a1, a2).Replace(" ", "&nbsp"))
                Response.Write(String.Format("{0,-10:*}{0,-10:*}<br>", a1, a2).Replace(" ", "&nbsp"))
                Response.Write(String.Format("{0,-10:*}{0,-10:*}<br>", a1, a2).Replace(" ", "&nbsp"))
                Response.Write(String.Format("{0,-10:*}{0,-10:*}<br>", a1, a2).Replace(" ", "&nbsp"))结果:
    asdf      asdf      
    asdf      asdf      
    asdf      asdf      
    asdf      asdf      
      

  4.   

    ----->
    Response.Write(String.Format("{0,-10:*}{1,-10:*}", a1, a2).Replace(" ", "&nbsp"))
      

  5.   

    Response.Write((a1.PadRight(10) + a2.PadRight(10) + "<br>").Replace(" ", "&nbsp"))
                Response.Write((a1.PadRight(10) + a2.PadRight(10) + "<br>").Replace(" ", "&nbsp"))
                Response.Write((a1.PadRight(10) + a2.PadRight(10) + "<br>").Replace(" ", "&nbsp"))
                Response.Write((a1.PadRight(10) + a2.PadRight(10) + "<br>").Replace(" ", "&nbsp"))
      

  6.   

    我感觉C#认为一个汉字是一位,所以如果输出成文本。
    如果A1=“张三”,A2=“张三三”,用string.format
    是这样的string.format("{0:-6}{1:-6}",a1,a2)
    |张三    |
    |张三三   |
      

  7.   

    s = "iam方枪枪";int len = s.Length;//will output as 6byte[] sarr = System.Text.Encoding.Default.GetBytes(s);len = sarr.Length;//will output as 3+3*2=9