c# - 如何在不同字符之间拆分字符串

标签 c# string split

我在拆分字符串时遇到问题。我只想拆分 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/

相关文章:

php - '0' 作为 PHP 中带有 empty() 的字符串

C# 内存模型、锁定和同步

c# - 在 sql server 上从 C# 运行查询

javascript - 如何将日期字符串标准化为 YYYY.MM.DD 格式?

javascript - JS - 读取 XML 标签之间的数据

javascript - JavaScript 中的正则表达式 .split()

php - 将 {} 内的 CSS 拆分为键/值对数组

c# - 如何将值四舍五入到小数点后三位?

c# - 使用 Parallel.Invoke 和静态变量时的奇怪行为

python - 如何将字符串字符转换为列表?