Foreach wont split a string
Posted
by Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2010-04-15T09:40:42Z
Indexed on
2010/04/15
9:43 UTC
Read the original article
Hit count: 178
c#
//assign variables
string measurementIn;
//read in file in array
string[] lines = File.ReadAllLines("../../convert.txt");
//ask user for date
Console.WriteLine("Enter the conversion in the form (amount,from,to)");
measurementIn = Console.ReadLine();
//array for splitting input
string[] conversionArray = measurementIn.Split(',');
Console.WriteLine("{0} , {1} , {2}", conversionArray[0], conversionArray[1], conversionArray[2]);
Console.ReadLine();
//check lines for conversion
foreach (string line in lines)
{
//array for the measurement
string[] measurementArray = line.Split(',');
Console.WriteLine("{0}", measurementArray[0]);
© Stack Overflow or respective owner