Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Read a file ang extract strings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
J-L - 25 Mar 2008 10:45 GMT
Hi,

I need to read a file like this:

# Messages français pour GNU gettext.
# Copyright © 2006 Yoyodyne, Inc.
# Michel Robitaille <robitail@IRO.UMontreal.CA>, 2006.
# Christophe Combelles <ccomb@free.fr>, 2006
#
msgid ""
msgstr ""
"Project-Id-Version: GNU hello-pascal 0.15-pre5\n"
"Report-Msgid-Bugs-To: bug-gnu-gettext@gnu.org\n"
"PO-Revision-Date: 2006-10-01 02:29+0200\n"
"Last-Translator: Christophe Combelles <ccomb@free.fr>\n"
"Language-Team: French <traduc@traduc.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: hello.hello_world
msgid "Hello, world!"
msgstr "Bonjour, le monde !"

#: hello.running_as
#, object-pascal-format
msgid "This program is running as process number %d."
msgstr "Ce programme est exécuté en tant que processus numéro %d."

and get a sortedlist with all msgid as keyz and msgstr as values.
"Hello, world!" = "Bonjour, le monde !"
"This program is running as process number %d." = "Ce programme est
exécuté en tant que processus numéro %d."

What's the best solution to do this please ?

Read all strings "one by one" ?

Jean-Luc !
Jon Skeet [C# MVP] - 25 Mar 2008 12:34 GMT
<snip>

> What's the best solution to do this please ?
>
> Read all strings "one by one" ?

Yes, I'd read a line at a time and process lines I'm interested in.
I'd personally create a class to encapsulate the key and the value,
but you could also reuse the generic KeyValuePair struct.

When you say you want a *sorted* list, what do you want it sorted by?
If it's just "where the entries came" then you just need a List which
you add to at the end each time.

Jon
J-L - 25 Mar 2008 14:13 GMT
> Yes, I'd read a line at a time and process lines I'm interested in.
> I'd personally create a class to encapsulate the key and the value,
[quoted text clipped - 3 lines]
> If it's just "where the entries came" then you just need a List which
> you add to at the end each time.

But how to use a List<> to get  key / value elements ?
After, I need to get value efficiently with (for example)
MyList["mykey"]
Jon Skeet [C# MVP] - 25 Mar 2008 14:14 GMT
> > When you say you want a *sorted* list, what do you want it sorted by?
> > If it's just "where the entries came" then you just need a List which
[quoted text clipped - 3 lines]
> After, I need to get value efficiently with (for example)
> MyList["mykey"]

Ah - you didn't say that. In that case use a List for the "in order"
version and a Dictionary for key lookups.

Jon
J-L - 25 Mar 2008 16:19 GMT
> Ah - you didn't say that. In that case use a List for the "in order"
> version and a Dictionary for key lookups.

Finally, I use a Dictionnary. Thanks for your help

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.