Read a file ang extract strings

J

J-L

Hi,

I need to read a file like this:

# Messages français pour GNU gettext.
# Copyright © 2006 Yoyodyne, Inc.
# Michel Robitaille <[email protected]>, 2006.
# Christophe Combelles <[email protected]>, 2006
#
msgid ""
msgstr ""
"Project-Id-Version: GNU hello-pascal 0.15-pre5\n"
"Report-Msgid-Bugs-To: (e-mail address removed)\n"
"PO-Revision-Date: 2006-10-01 02:29+0200\n"
"Last-Translator: Christophe Combelles <[email protected]>\n"
"Language-Team: French <[email protected]>\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 !
 
J

Jon Skeet [C# MVP]

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

J-L

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.


But how to use a List<> to get key / value elements ?
After, I need to get value efficiently with (for example)
MyList["mykey"]
 
J

Jon Skeet [C# MVP]

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.

But how to use a List<> to get key / value elements ?
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

J-L

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
 
Top