0

I have read much about .resx files and know that we can also create a custom resource provider which may support db or XML.

I have a requirement however where my keys will contain spaces. Plus I want them in a simple .txt file. No .resx or XML files.

An example would be like:

My Key 1=Hello Dude
My Key 2=Hello world

I was wondering if there is any way to fetch such keys in .net by writing some custom resource provider in C#. Is it possible?

Faisal Mq
  • 5,036
  • 4
  • 35
  • 39

1 Answers1

0

Would JSON format do?

var someText = "{\"my key 1\" : \"hello dude\", \"my key 2\" : \"hello world\"}";

JObject resource = JObject.Parse(someText);

foreach (var p in resource.Properties())
{
    Console.WriteLine("The key is {0} and it's value is {1}", p.Name, p.Value);
}

Dependency: JSON.Net

Hth...

EdSF
  • 11,753
  • 6
  • 42
  • 83
  • Don't need json. Just a simple text file with key=value format – Faisal Mq Dec 10 '17 at 11:03
  • 1
    @FaisalMushtaq Yes, that's what JSON _format_ is, keys and values, and can be saved in a `txt` "file" (or `.json`, or whatever extension). If that's too much then you can save a text file exactly like how you typed it and just parse it. One key/value pair per line, delimited by an `=` or whatever delimiter you choose..and gets us to simple CSV or TSV etc _formatted_ files. – EdSF Dec 11 '17 at 03:15