Click here to Skip to main content
15,845,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file contains data in the format


how I can convert the data after reading to the format

100 10:24 11:34
200 9:40 12:45

as result I want to combine all line starts with 100 in single line 100 is a key and starts with 200 in line so the first column is a key

Create a Dictionary<int, string >() object
Open the file
for each line use "Split" to split on ";" which gives an array of strings
Convert the first item in the array (the 100, 200 etc) to an int
Check if that int exists as a key in your dictionary (use ContainsKey)
if the key doesn't exist, add it with the value being the second item in the array
if the key does exist, get the associated string and append a space and then the second item in the array

Create a new file
Now loop through each key item in the dictionary and write out the key plus a space plus the string value

To pre-empt your next question, no I won't "give you the code", it should be simple enough to convert the pseudo code above into actual code.
Share this answer
Frankie-C 1-Jun-15 6:22am    
you can use LINQ

Dim lines = File.ReadAllLines(filepath).Select(Function(record) record.Split(";"C)).Where(Function(cell) cell.Length >= 2).GroupBy(Function(x) x(0)).Select(Function(x) x.Key + " " + String.Join(" ", x.Select(Function(y) y(1))))

File.WriteAllLines(filepath, lines)

reference to read:[^][^][^][^][^][^]
Share this answer
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900