Sharkheart
Sharkheart

Reputation: 15

get a word after specific word/character from .txt file

to the point, i've problem with getting word/string after specific word or character from .txt file, this is the txt file

andrea = bad
john = good
rob = evil

so when input is andrea the output is bad, when input john the output is good, and when input is rob the output is evil

i just want the word after "=" are showed up when first word is inputted, all lines in the file structured like that.

sorry for my poor english, i hope you understand what i asked

Upvotes: 1

Views: 866

Answers (1)

I4V
I4V

Reputation: 35363

var dict = File.ReadLines(filename)
                    .Select(line => line.Split('='))
                    .Where(parts => parts.Length>1)
                    .ToDictionary(x=>x[0].Trim(), x=>x[1].Trim());

Console.WriteLine(dict["andrea"]);

Upvotes: 1

Related Questions