I have the following strings in a text file "test"
Table Name.type
Market Drinks.tea
I wana split the strings so that I get the following output
ObjectName = Table AttributeName = Name Attribute Type =type
ObjectName = Market AttributeName = Drinks Attribute Type =tea
here is my code
string[] lines = File.ReadAllLines(@"d:\test.txt");
int i = 0;
var items = from line in lines
where i++ != 0
select new{
objectName = line.Split(new char[] {' '})[0],
attrName = line.Split(new char[]{'.'})[1],
attrType = line.Split(new char[] { ' ' })[2]
};
foreach (var item in items)
{
Console.WriteLine("ObjectName = {0}, AttributeName = {1}, Attribute Type = {2}",
item.objectName, item.attrName, item.attrType);
}
I'm getting an out of boundaries exception.
PS: there are no spaces at the end of the strings in the text file I just wanted to test a character!