当前位置:K88软件开发文章中心编程语言.NET.NET01 → 文章内容

C#中String.Insert在字符串中间某个位置插入另一个字符串

减小字体 增大字体 作者:mynetcode     来源:asp编程网  发布时间:2018-12-30 6:52:48

功能:在一个字符串中插入另一个字符串
函数:string.Insert(int Index,string InsertStr)
参数:Index为位置,不能为负数;InsertStr要插入的字符串,不能为空
举例:str = "20170505151617";要将这样的字符串转成str = "2017-05-05 15:16:17"
具体代码:
string str = "20170505151617";            
str = str.Insert(4, "-");
str = str.Insert(7, "-");
str = str.Insert(10, " ");
str = str.Insert(13, ":");
str = str.Insert(16, ":");
MessageBox.Show(str);

C#中String.Insert在字符串中间某个位置插入另一个字符串