|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
efficient routine to parse a text stringa:18: {i:0;i:408;i:1;i:409;i:2;i:410;i:3;i:411;i:4;i:413;i:5;i:414;} a: = page_id a:18 -> page_id = 18 Those within curly brackets { } i:0;i:408 the 1st group i:0; i : section order within a page (in this case page with page_id = 18) i:0 -> section_order = 0 (top of page) the 2nd group i:408; i: section_id i:408 -> section_id = 408 therefore, {i:0;i:408;} -> section_id 408 has section_order_id 0 This is a weird way to arrange data. I'd rather assign a different letter to section_id so that the above example can be rewritten as: a:18{i:0;s:408;...} where s = section_id By the way, if you're familiar with or care about phpWebsite CMS (LAMP or LinuxApacheMysqlPhp world), this come from the page master mod in their open source app. I'm trying to penetrate their world with .NET :-) Your help regarding the parsing routine is greatly appreciated. Bill "Bill nguyen" <billn_nospam_please@jaco.com> wrote in Have you taken a look at regular expressions? It would be perfect for news:e7DBfnh6GHA.4996@TK2MSFTNGP03.phx.gbl: > I'm looking for a good routine to parse the following text pattern: > > a:18: {i:0;i:408;i:1;i:409;i:2;i:410;i:3;i:411;i:4;i:413;i:5;i:414;} parsing your data : ) I think reg ex is what I have to take a look. My question is still about an
efficient method to parse and insert the data elements into a datarow. Thanks Bill Show quoteHide quote "Spam Catcher" <spamhoneypot@rogers.com> wrote in message news:Xns9855D5D047605usenethoneypotrogers@127.0.0.1... > "Bill nguyen" <billn_nospam_please@jaco.com> wrote in > news:e7DBfnh6GHA.4996@TK2MSFTNGP03.phx.gbl: > >> I'm looking for a good routine to parse the following text pattern: >> >> a:18: {i:0;i:408;i:1;i:409;i:2;i:410;i:3;i:411;i:4;i:413;i:5;i:414;} > > > Have you taken a look at regular expressions? It would be perfect for > parsing your data : ) > > "Bill nguyen" <billn_nospam_please@jaco.com> wrote in Write a regular expression to parse the string into two sections:news:#xeRh0u6GHA.2380@TK2MSFTNGP02.phx.gbl: > I think reg ex is what I have to take a look. My question is still > about an efficient method to parse and insert the data elements into a > datarow. a:18: {i:0;i:408;i:1;i:409;i:2;i:410;i:3;i:411;i:4;i:413;i:5;i:414;} ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A neat feature of .NET's regular expression is that you can reference components with a section. For example: {i:0;i:408;i:1;i:409;i:2;i:410;i:3;i:411;i:4;i:413;i:5;i:414;} is actually composed of subelements - so you can access each of these subelements (called group or named captures). More info is here: http://www.regular-expressions.info/named.html Once your string has been successfully parsed by the regular expression, loop over the second section, and retrieve each group - then stuff the results into a datatable and submit to a database. Your code should be pretty efficent - in summary: 1. A couple lines to prase the data 2. Retreive the matches from the regular expression 3. Loop over the second section's submatches (named captures) and fill in your data object. Here is a general tutorial on regular expressions: http://aspnet.4guysfromrolla.com/articles/022603-1.aspx
VB 6 developers and .Net
Read legacy vb5 files with variant declare in vb.net Running an Access macro from a VB.NETprogram How to assign value to a dropdown box items? ADOX add bool field need help on optional arg Overlapping controls Redrawing on GDI+ Set Focus to textbox on tab control clicking on a DataGridView's DataSource property throws exception in designer |
|||||||||||||||||||||||