TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Steve
NA
4
4.9k
StreamReader not reading the whole TXT File.
Aug 8 2012 6:51 PM
Hi there,
I was trying to make TXT reader which reads the whole file and Print some choosen lines with choosen characters.
But the StreamReader is not reading the whole file I want it to show the lines starting with "f" and "v" characters. its only showing Characters starting with v.
The code I'm using.
using System;
using System.IO;
using System.Collections.Generic;
public class CharsFromStr
{
public static void Main()
{
String SpecificSymbol = "#";
String SpecificSymbol1 = "m";
String SpecificSymbol2 = "o";
String SpecificSymbol3 = "u";
String SpecificSymbol4 = "s";
String SpecificSymbol5 = "v";
List<string> list = new List<string>();
using (StreamReader reader = new StreamReader("Data.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
char[] V1 = new char[line.Length];
char[] V2 = new char[line.Length];
char[] V3 = new char[line.Length];
StringReader sr = new StringReader(line);
if (line.StartsWith(SpecificSymbol))
{
continue;
}
if (line.StartsWith(SpecificSymbol1))
{
continue;
}
if (line.StartsWith(SpecificSymbol2))
{
continue;
}
if (line.StartsWith(SpecificSymbol3))
{
continue;
}
if (line.StartsWith(SpecificSymbol4))
{
continue;
}
sr.Read(V1, 0, 11);
sr.Read(V2, 0, 18-9);
sr.Read(V3, 0, 27-18);
list.Add(line); // Add to list.
//Console.WriteLine(line); // Write to console.
Console.WriteLine(V1);
Console.WriteLine(V2);
Console.WriteLine(V3);
}
string line2;
while ((line2 = reader.ReadLine()) != null)
{
char[] F1 = new char[line2.Length];
char[] F2 = new char[line2.Length];
char[] F3 = new char[line2.Length];
char[] F4 = new char[line2.Length];
StringReader sr = new StringReader(line2);
if (line2.StartsWith(SpecificSymbol))
{
continue;
}
if (line2.StartsWith(SpecificSymbol1))
{
continue;
}
if (line2.StartsWith(SpecificSymbol2))
{
continue;
}
if (line2.StartsWith(SpecificSymbol3))
{
continue;
}
if (line2.StartsWith(SpecificSymbol4))
{
continue;
}
if (line2.StartsWith(SpecificSymbol5))
{
continue;
}
sr.Read(F1, 0, 5);
sr.Read(F2, 0, 4 - 2);
sr.Read(F3, 0, 8 - 2);
sr.Read(F4, 0, 12 - 2);
list.Add(line2); // Add to list.
// Console.WriteLine(line); // Write to console.
Console.WriteLine(F1);
Console.WriteLine(F2);
Console.WriteLine(F3);
Console.WriteLine(F4);
}
Console.ReadLine();
}
}
}
and the .txt file i'm trying to load
# Blender v2.62 (sub 0) OBJ File: ''
# www.blender.org
mtllib test.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
usemtl Material
s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8
Reply
Answers (
1
)
Reading a text file by Line Numbers and ignoring Lines starting with "i" character.
Questions About dataGridView