Extract data from a file

Hi all,

I m pretty new with scala. I would like to know following:

I have a file that contains:

English:
Complete => a,b,c,d
Vowels => a,e,i,o,u

French:
Complete => a,b,c,d
Vowels => a,e,i,o,u

Etc. …

If based on the language (i choose for example French), what is the best way to extract the letters from the file if i decide to get vowels only for that specific language?

Hello, and welcome to the language and its community.

What have you tried?

I guess that, if you really want to learn, you would prefer advice rather than a block of code solving your problem. But for that, it may be better to start from what you have done.
Show us what was your idea, show us the code, tell us why it didn’t worked.

PS: On a very general form, what I would would be read the file line by line using Source.fromFile(filename).getLines(). Then I would parse each line assuming the format is as simple as your example, using a simple state machine, which will produce a Map[String, Language] where the key is the name of the language (e.g. "French") and the value is a case class as follows:

final case class Language(complete: Set[Char], vowels: Set[Char])

Hi,
Thx for the reply.
Would you advice to use regular expressions to get the language name (“french”) and the Language data of each line and add in the Map?

Yeah you would need to think in how to parse your data.

That is complex topic. First you need to define some kind of grammar for your input files.

For example, assuming the files are always like:

[language-name]
complete => [all-letters-separated-by-comma]
vowels => [all-vowels-separated-by-comma]

*repeat*

Then a simple state machine would work.

Ok thx for your help, your solution is interesting. I never did this before and understand your view but for me it s difficult to put it in proper working code. I will look for an other solution as like i said i m totally new at this