我在拆分字符串时遇到问题。我只想拆分 2 个不同字符之间的单词:
string text = "the dog :is very# cute";
我怎样才能只抓取 :
和 #
字符之间的单词,is very?
最佳答案
您可以使用 String.Split()
方法与 params char[]
;
Returns a string array that contains the substrings in this instance that are delimited by elements of a specified Unicode character array.
string text = "the dog :is very# cute";
string str = text.Split(':', '#')[1]; // [1] means it selects second part of your what you split parts of your string. (Zero based)
Console.WriteLine(str);
这是一个DEMO
.
您可以随意使用它。
关于c# - 如何在不同字符之间拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14797584/