String Manipulation in .net using C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jay123
    New Member
    • Sep 2008
    • 121

    String Manipulation in .net using C#

    hi all,
    i have a string of type
    <a><b><c>123</c></b></a> ( i know it looks like xml data, and it is but i have an array of these strings)

    now what i want to do is get value in 'c' node. i thought of using substring but as value of 'c' node may change from 5 to any number of characters. i have tried couple of more things but m unable to get it right.

    any help will be appreciated
  • jay123
    New Member
    • Sep 2008
    • 121

    #2
    Code:
           int searchchr = Data[i].IndexOf("<c>");
                    int endchr = Data[i].IndexOf("</c>");
                    int chr = endchr - (searchchr + 3);
                    string name = Data[i].Substring(searchchr + 3, chr);

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Have you considered using RegularExpressi ons to extract the data?

      There are a bunch of examples on how to use them here.

      Comment

      • rvarshney
        New Member
        • Feb 2009
        • 10

        #4
        Hi,

        RegularExpressi ons are the best way to do this...

        alternatively you can look at the APIs of System.Xml namespace where you can load an xml string and can analyze them in the way you wish.

        Hope this helps.

        Comment

        Working...