[REPOST]如何查找的....的个数? [英] [REPOST] How to find howmany number of 's ....?

查看:73
本文介绍了[REPOST]如何查找的....的个数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string orderlist = "<ol><li>ONE</li><li>TWO</li><li>THREE</li></ol>";


在此字符串中,如何查找< li>的数量.的?

其实我想要这样的输出...?

1.一个
2.两个
3.三个


In this string, how to find howmany no.of <li> ''s ?

Actually I want an output like this...?

1. ONE
2. TWO
3. THREE

推荐答案

您需要使用这些节点来解析字符串,就像我们对XML字符串反序列化时一样.
You need to parse the string using those nodes, just like we do while deserializing an xml string.


由于这不是完全的转贴-只是非常非常非常...

您已获得一个正则表达式,该正则表达式返回HTML的文本内容.您只需要扩展它即可将"li"部分中的文本提取为单独的匹配项,然后对其进行处理.
由于您仅对"li"部分感兴趣,因此将正则表达式更改为:
Since this isn''t quite a repost - just very, very, very nearly...

You have been given a regex which returns the text content of the HTML. You just need to expand it to extract the text from the "li" section into separate matches, and then process them.
Since you are only interested in the "li" sections, It may be worth your while changing the regex to:
string inputText = "<ol><li>ONE</li><li>TWO</li><li>THREE</li></ol>";
Regex regex = new Regex("(?<=\\<li\\>)[^\\<]*(?=\\</li\\>)",
                        RegexOptions.IgnoreCase
                        | RegexOptions.CultureInvariant
                        | RegexOptions.IgnorePatternWhitespace
                        | RegexOptions.Compiled);
MatchCollection ms = regex.Matches(inputText);
string outText = "Matches:\n";
foreach (Match m in ms)
    {
    outText += m.Groups[0].Value + "\n";
    }

我强烈建议您访问 www.ultrapico.com [

I would strongly suggest you go to www.ultrapico.com[^] and D/L a copy of Expresso - it helps design, explain and test regular expressions. It''s free, it generates C# or VB code for you, and it works brilliantly - I wish I''d written it!


查找任何li's

For finding no of li''s

string li = "<ol><li>ONE</li><li>TWO</li><li>THREE</li></ol>";
        Regex regex = new Regex(@"li");
        int count = regex.Matches(li).Count;



有关其他内容,请参见OrginalGriff的答案.



For other stuff see OrginalGriff''s answer.


这篇关于[REPOST]如何查找的....的个数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆