C#插入和填充字符串 官网
C#中插入字符串用Insert方法,它能在指定位置插入另一个字符串。填充字符串可用PadLeft和PadRight方法,PadLeft从左侧填充,PadRight从右侧填充。 string str = "Hello";string insertResult = str.Insert(2, "ABC"); // 在索引2处插入ABC,运行结果:HeABCllostring padLeftResult = str.PadLeft(8, '*'); // 从左侧填充到长度为8,用*填充,运行结果:***Hello 使用Insert方法时,插入位置要在字符串有效索引范围内;使用PadLeft和PadRight方法时,填充长度要大于原字符串长度才有填充效果。