views:

83

answers:

2

hi all

i have just started learning linq because i like the sound of it. and so far i think im doing okay at it.

i was wondering if Linq could be used to find the following information in a file, like a group at a time or something:

Control
Text
Location
Color
Font
Control Size

example:

Label
"this is text that will
appear on a label control at runtime"
23, 77
-93006781
Tahoma, 9.0, Bold
240, 75

The above info will be in a plain file and wil have more than one type of control and many different sizes, font properties etc associated with each control listed. is it possible in Linq to parse the info in this txt file and then convert it to an actual control?

i've done this using a regex but regex is too much of a hassle to update/maintain.

thanks heaps

jase


Edit:
Since XML is for structured data, would Linq To XML be appropriate for this task? And would you please share with me any helpful/useful links that you may have? (Other than MSDN, because I am looking at that now. :))

Thank you all

+1  A: 

LINQ is good for filtering off rows, selecting relevant columns etc.

Even if you use LINQ for this, you will still need regex to select the relevant text and do the parsing.

Ngu Soon Hui
thank you Ngu Soon Hui. What about Linq To XML? Would regex be required if i use Ling To XML?
baeltazor
Depends on your application, but if you are just storing and retrieving data in tree manner, then no..
Ngu Soon Hui
thank you for your help and advice i really appreciate it Ngu Soon Hui
baeltazor
+2  A: 

If you are generating this data yourself, then I HIGHLY recommend you store this in an XML file. Then you can use XElement to parse this.

EDIT: This is exactly the type of thing that XML is designed for, structured data.

EDIT EDIT: In response to the second question, Linq to XML is exactly what your looking for:

For an example, here is a couple of links to code I have written that parses XML using XElements. It also creates a XML document.

Example 1 - Loading and Saving: have a look under the FromXML() and ToXML() methods.

Example 2 - Parsing a large XML doc: have a look under the ParseXml method.

Hope these get you going :D

Alastair Pitts
Thank you, AP Erebus. So, Would Linq To XML be what I am looking for?
baeltazor
thankk you ap erebus
baeltazor
those were awesome mate thank you very much! i've completely changed my whole app around, it's so much faster now and a whole lot easier to use/maintain thank you so much
baeltazor