当前位置:asp编程网>技术教程>Net教程>  正文

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

2017-07-05 10:37:06   来源:www.aspbc.com   作者:mynetcode   浏览量:3658   收藏
功能:在一个字符串中插入另一个字符串
函数: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);

关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网