Reputation: 1395
This doesnt work:
string fileContent = Resource.text;
StreamReader read = File.OpenText(fileContent);
string line;
char[] splitChar = "|".ToCharArray();
while ((line = read.ReadLine()) != null)
{
string[] split = line.Split(splitChar);
string name = split[0];
string lastname = split[1];
}
read.Dispose();
How do you open a resource file to get its contents?
Upvotes: 3
Views: 10414
Reputation: 8462
to read resources, you need a special Stream named "ResourceReader", you can use it like this :
string fileContent = "<your resource file>";
using (ResourceReader reader = new ResourceReader(fileContent))
{
foreach (IDictionaryEnumerator dict in reader)
{
string key = dict.Key as string;
object val = dict.Value;
}
}
Upvotes: 0
Reputation: 1039428
Try like this:
string fileContent = Resource.text;
using (var reader = new StringReader(fileContent))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] split = line.Split('|');
string name = split[0];
string lastname = split[1];
}
}
Upvotes: 5
Reputation: 1092
I think the variable fileContent already has all the contents you need.
Upvotes: 0