- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace readfrom_textfile {
- class Program {
- static void Main(string[] args) {
- var fileStream = new FileStream(@"D:\Practise\test.txt", FileMode.Open, FileAccess.Read);
- using(var streamReader = new StreamReader(fileStream, Encoding.UTF8)) {
- string line;
- while ((line = streamReader.ReadLine()) != null) {
- string[] data = line.Split(new char[] {
- '('
- }, StringSplitOptions.RemoveEmptyEntries);
- string bikeName = data[0].Trim().Split(' ').Last();
- bikeNamebikeName = bikeName.Remove(bikeName.Length - 1);
- string[] usageData = data[1].Split(new char[] {
- ';'
- }, StringSplitOptions.RemoveEmptyEntries);
- string issuedBike = usageData[0].Trim().Split(' ')[2];
- string inUseBike = usageData[1].Trim().Split(' ')[2];
- Console.WriteLine("Name:" + bikeName);
- Console.WriteLine("Total:" + issuedBike);
- Console.WriteLine("InUse:" + inUseBike);
- Console.WriteLine();
- }
-
- }
- Console.ReadLine();
- }
My text file contains:
Users of Yamaha: (Total of 2 bike issued; Total of 2 bike in use). line1....................something
line 2..................something
Bike details //emptyline
1125 Monica YamahaR15(v3.0)(petrol / 7788 4903), start Wed 1 / 18 8: 53 1128
Dhini Yamaha Fz(v2.0)(petrol / 7748 4903), start Wed 1 / 18 9: 53
O/p like this...
- Name: Yamaha;
- Total: 1;
- Inuse: 1;
- members: Monica[Wed 1 / 18 8: 53], Dhini[Wed 1 / 18 9: 53]
I did something fine using my code but i can't achieve 100%.Please help me to solve the problem.