c# - 检索特定模式内的值

标签 c# regex .net-2.0

我有一个这样的模式

"The world is #bright# and #beautiful#"

我需要在 # # .. 任何指针中检索字符串 "bright","beautiful"


我的解决方案(感谢 Bolu):

string s = "The world is #bright# and #beautiful#";
    string[] str = s.Split('#');
    for (int i = 0; i <= str.Length - 1; i++)
    {
        if (i % 2 != 0)
        {
            Response.Write(str[i] + "<br />");
        }
    }

最佳答案

如果你想要的只是##中的字符串,那么不需要正则表达式,只需使用string.Split:

string rawstring="The world is #bright# and beautiful";
string[] tem=rawstring.Split('#');

之后,您只需从 string[] tem 中获取偶数项(索引:1,3,5....)

关于c# - 检索特定模式内的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3736133/

相关文章:

php - PHP 中更高效的字符串清理正则表达式

正则表达式:匹配除特定模式之外的所有内容

c# - 使用 C# 以编程方式更新 xml

c# - WPF DataGrid bool 字段显示为 true/false 而不是复选框

c# - 应用程序数据的常用存储位置在哪里

c# - 按顺序获取文件中的行的最佳方法?

c# - 如何使用 log4net 在日志文件中添加一个空行?

python - 从主机字符串中删除最后一个句点

正则表达式验证端口号

c# - 堆栈集合在 C# 2.0 中缺少 shift 和 unshift