Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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:

C#
   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";


}
Posted
Updated 25-Jun-16 9:49am
v3
Comments
Tomas Takac 24-Jun-16 8:16am    
Your regex is wrong. In your text there is the attribute align=justify which you are omitting from your regex. Moreover regex is case sensitive by default. Last but not least b, c, aA, bA are not good variable names.
RickZeeland 24-Jun-16 14:07pm    
Maybe you should use:
new Regex("(<P.*?\\/p>)", RegexOptions.Singleline);
Matt T Heffron 24-Jun-16 22:18pm    
Even if you fix the Regex as suggested, the example you give will have aA with 3 elements and bA with 4.
What is it that you are really trying to accomplish?
(BTW. All of the .ToString() of the aA[i] and bA[i] are pointless, the values are already strings!)

1 solution

Quote:
“Length of aA isnt matching length of bA”.
This message comes from your own code, it just mean that
C#
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.
 
Share this answer
 
v2
Comments
Afzaal Ahmad Zeeshan 25-Jun-16 18:29pm    
5ed.
Patrice T 25-Jun-16 18:31pm    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900