【发布时间】:2011-11-25 10:12:05
【问题描述】:
只是想知道,如果我有字符串:
Hello#World#Test
我如何删除#,然后在三个单独的字符串中包含Hello、World 和Test,例如称为:
String1 和 String2 和 String3
【问题讨论】:
只是想知道,如果我有字符串:
Hello#World#Test
我如何删除#,然后在三个单独的字符串中包含Hello、World 和Test,例如称为:
String1 和 String2 和 String3
【问题讨论】:
您可以将它们放在一个字符串数组中,做一些简单的事情:
string[] s = "Hello#World".Split('#');
s[0] 包含“Hello”,s[1] 包含“World”
有关拆分的更多信息,请参见此处:http://msdn.microsoft.com/en-us/library/b873y76a.aspx
【讨论】:
String.Split("#".ToCharArray()) 将返回一个带有两个元素的 string[]。
Element0 将是“Hello”,Element1 将是“World”
【讨论】:
这是一种方式
"hello#world".Split('#');
【讨论】: