- ·上一篇文章:c#中如何使用\r\n作为split的分割字符串
- ·下一篇文章:C#的winform程序如何使里面的控件随窗口变大而等比变大?
C#中String.Insert在字符串中间某个位置插入另一个字符串
功能:在一个字符串中插入另一个字符串
函数: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);
函数: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在字符串中间某个位置插入另一个字符串