473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

efficient routine to parse a text string

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;}

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

Oct 7 '06 #1
3 1591
"Bill nguyen" <bi*****************@jaco.comwrote in
news:e7**************@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 : )
Oct 8 '06 #2
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

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Bill nguyen" <bi*****************@jaco.comwrote in
news:e7**************@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 : )


Oct 8 '06 #3
"Bill nguyen" <bi*****************@jaco.comwrote in
news:#x**************@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.

Write a regular expression to parse the string into two sections:

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
Oct 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fowlertrainer | last post by:
Hi ! Sorry, but zope@zope.org is not send mails to me... So I trying with that list... 1.) I want to use query-string, and post datas in combined dictionary. I have a page that I must...
22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
13
by: temp | last post by:
Hi all, I know this is easy for you guys but I am not a VB developer. My boss just wanted me to generate a mapping of all the queries in our Access DB. So I managed to create some subroutines to...
3
by: Daniel Weinand | last post by:
hello ng, i have a problem and a imho an insufficient method of solution. strings should be sorted by specific text pattern and dispayed in groups. the strings are stored in a db and have the...
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
4
by: Steven Blair | last post by:
Hi, I get passed a string like these examples: 3.1 4.23 1.1 5 I need to seperate the values into two integer variables.
9
by: igor.tatarinov | last post by:
Hi, I am pretty new to Python and trying to use it for a relatively simple problem of loading a 5 million line text file and converting it into a few binary files. The text file has a fixed format...
5
by: Just_a_fan | last post by:
I tried to put an "on error" statement in a routine and got the message that I cannot user "on error" and a lamda or query expression in the same routine. Help does not list anything useful for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.