利用构造方法,可以指定一个字符重复的次数string s = new String('A', 4);但这种方法不灵活。 可以利用字符串填充函数c.ToString().PadLeft(4,'B'),指定字符宽度为4,左面留空格,空格部分用B来填充 当然也可以自己写个函数 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace TestConApp { class Program { static void Main(string[] args) { //方法一 //利用构造方法 string s = new String('A', 4); Console.WriteLine(s); char c = 'A'; //方法二 //利用字符串填充函数,空格在左边 Console.WriteLine(c.ToString().PadLeft(4)); //空格可以填充其他任意字符 Console.WriteLine(c.ToString().PadLeft(4,'B')); //利用字符串填充函数,空格在右边 Console.WriteLine(c.ToString().PadRight(4)); //空格可以填充其他任意字符 Console.WriteLine(c.ToString().PadRight(4, 'B')); //方法三 //自己写函数 Console.WriteLine(Repeat('A', 4)); //让一个字符或字符串占指定宽度显示 string name = "Tom"; Console.WriteLine(name.PadLeft(4)); } //让一个字符重复指定次数的函数的方法 public static string Repeat(char c, int n) { string str = ""; while (n-- > 0) { str += c; } return str; } } } 运行结果: 利用PadLeft()函数和PadLeft()函数,可以用来格式化字符或字符串的显示,让一个字符或字符串占指定宽度显示