学校排行榜

(0)

投一票

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方法时,填充长度要大于原字符串长度才有填充效果。
专业
评论
新闻
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。