如何解析字符串? [英] How to parse string?

查看:121
本文介绍了如何解析字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为下面的my函数解析以下输入字符串,但我不断得到异常aA的长度与bA的长度不匹配。



我尝试使用正则表达式进行过滤,但我仍然在努力解析它。任何建议都会非常有帮助。谢谢。



I am trying to parse the following input string for the my function below, but I keep getting the exception "Length of aA isnt matching length of bA".

I have tried using regex to filter through but I am still struggling to get it parsed. Any suggestions would be very helpful. Thank you.

String a = Illiquidity option, credit model minted, Pricing service unveiled

string b = <P align=justify>RiskSpan has released a proprietary independent daily pricing service for structured products and mortgage assets. Real-time pricing and can process thousands of securities in virtually minutes, it says.</P><P align=justify>Joe Sturtevant, co-founder and pricing executive at RiskSpan, comments: "We are now pricing bonds in the manner in which a trader would and providing context that streamlines the audit process."</P>, <P align=justify>RiskSpan has released a proprietary independent daily pricing service for structured products and mortgage assets. Real-time pricing and can process thousands of securities in virtually minutes, it says.</P><P align=justify>Joe Sturtevant, co-founder and pricing executive at RiskSpan, comments: "We are now pricing bonds in the manner in which a trader would and providing context that streamlines the audit process."</P>





我是什么尝试过:





What I have tried:

   string a = testtitle();
   string b = testStory();

    string c = "";
    string results = "";

    string[] aA = a.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

   // Regex rgxPTag = new Regex("(<p>.*?<\\/p>)");
    Regex rgxPTag = new Regex("(<p>.*?<\\/p>)", RegexOptions.Singleline);
    string[] bA = rgxPTag.Matches(b).Cast<match>().Select(m => m.Groups[1].Value).ToArray();

    if (aA.Length == bA.Length)
    {

        for (int i = 0; i < aA.Length; i++)
        {
            DateTime dt = DateTime.Today;

            XDocument doc = new XDocument(
       new XDeclaration("1.0", "gb2312", string.Empty),
       new XElement("article",
           new XElement("status", "Approved"),
            new XElement("title", aA[i].ToString()),
             new XElement("subtitle", aA[i].ToString()),
              new XElement("synopsis", bA[i].ToString() + "..."),
               new XElement("url", c),
                new XElement("display_date", dt.ToShortDateString())
         ));
             results  = results  + Environment.NewLine + doc.ToString();

        }
        return results;
    }
    return "Length of aA isnt matching length of bA";


}

推荐答案

Quote:

aA的长度与bA的长度不匹配。

"Length of aA isnt matching length of bA".

此消息来自您自己的代码,它只是意味着

This message comes from your own code, it just mean that

if (aA.Length == bA.Length)



失败。

你是唯一一个知道为什么这个测试在这里以及它意味着什么的人。 />


使用调试器查看代码正在执行的操作。


Failed.
You are the only one know why this test is here and what it means.

Use the debugger to see what your code is doing.


这篇关于如何解析字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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