C# 在字符串指定位置之前插入新的字符串

http://zhidao.baidu.com/link?url=XbU4souNCiDk9AbdYWMDj6VMO7AxlnIpcEnAy4JgfaZXxlpjVt2cEoL6GPO9B0WytMq5SbDVIqsjZ8bJd0riv2xSnFSWzHFkzX4P9rHAIC_

static void Main(string[] args)

{

  string str = "qewdesdfdfdfd.txt";

  string insertStr = "123";

  // 找到最后一个【.】点的位置,然后插入你想插入的字符

  string result = str.Insert(str.LastIndexOf('.'), insertStr);

  Console.WriteLine(result);

  Console.ReadLine();

}

运行结果:

posted @ 2016-07-06 18:13  霓裳依旧  阅读(14689)  评论(0编辑  收藏  举报