Click here to Skip to main content
16,008,490 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to extract Image metadata Pin
Eric Dahlvang28-Aug-06 11:33
Eric Dahlvang28-Aug-06 11:33 
QuestionParse a text file into an object Pin
AndyHug28-Aug-06 8:41
AndyHug28-Aug-06 8:41 
AnswerRe: Parse a text file into an object Pin
Ed.Poore28-Aug-06 9:14
Ed.Poore28-Aug-06 9:14 
AnswerRe: Parse a text file into an object Pin
Not Active28-Aug-06 9:15
mentorNot Active28-Aug-06 9:15 
AnswerRe: Parse a text file into an object Pin
SomeGuyThatIsMe28-Aug-06 9:16
SomeGuyThatIsMe28-Aug-06 9:16 
GeneralRe: Parse a text file into an object Pin
Guffa28-Aug-06 9:35
Guffa28-Aug-06 9:35 
GeneralRe: Parse a text file into an object Pin
SomeGuyThatIsMe28-Aug-06 9:42
SomeGuyThatIsMe28-Aug-06 9:42 
GeneralRe: Parse a text file into an object Pin
AndyHug28-Aug-06 9:41
AndyHug28-Aug-06 9:41 
I must select the "not very good way" and to open the file into a stream and use ReadLine() to grab each line and put it into a string, then fall through a switch on the first character so I know what kind of object to use
This part I know how to do it ... The don't know part is how to use the fields and C# classes to create this single object I need. Some one sent me some code in VB.NET that I think it seems like i need, only that I need it in C#. If you have something similar please send at least some explanations.

The VB code :

Private Sub ParseFile(ByVal filename As String)
Dim headers As New HeaderCollection
Dim reader As IO.StreamReader
While reader.Peek <> -1
Dim line As String = reader.ReadLine
Select Case line.Substring(0, 1)
Case "H"
headers.Add(line)
Case "I"
headers.LastItem.InformationList.Add(line)
Case "C"
headers.LastItem.InformationList.LastItem.Comments.Add(line)
Case "E"
headers.LastItem.Footer = line
End Select
End While
End Sub
Private Sub WriteFile(ByVal filename As String, ByVal headers As HeaderCollection)
Dim writer As IO.StreamWriter = New IO.StreamWriter(filename, True)

For Each h As Header In headers
writer.WriteLine(h.Text)
For Each i As Information In h.InformationList
writer.WriteLine(i.Text)
For Each c As Comment In i.Comments
writer.WriteLine(c.Text)
Next
Next
writer.WriteLine(h.Footer)
Next

writer.Flush()
writer.Close()
End Sub

Public Class Header
Private _informtions As New InformationCollection
Public Text As String
Public Footer As String
Public Property InformationList() As InformationCollection
Get
Return _informtions
End Get
Set(ByVal Value As InformationCollection)
_informtions = Value
End Set
End Property
End Class
Public Class Information
Private _comments As New CommentCollection
Public Text As String
Public Property Comments() As CommentCollection
Get
Return _comments
End Get
Set(ByVal Value As CommentCollection)
_comments = Value
End Set
End Property
End Class
Public Class Comment
Public Text As String
End Class
Public Class HeaderCollection
Inherits CollectionBase
Public Overloads Sub Add(ByVal Text As String)
Dim h As New Header
h.Text = Text
List.Add(h)
End Sub
Default Public Property Item(ByVal index As Integer) As Header
Set(ByVal Value As Header)
Me.List(index) = Value
End Set
Get
Return DirectCast(Me.List(index), Header)
End Get
End Property
Public ReadOnly Property LastItem() As Header
Get
Return DirectCast(Me.List(Me.List.Count - 1), Header)
End Get
End Property
End Class
Public Class InformationCollection
Inherits CollectionBase
Public Sub Add(ByVal Text As String)
Dim i As New Information
i.Text = Text
List.Add(i)
End Sub
Default Public Property Item(ByVal index As Integer) As Information
Set(ByVal Value As Information)
Me.List(index) = Value
End Set
Get
Return DirectCast(Me.List(index), Information)
End Get
End Property
Public ReadOnly Property LastItem() As Information
Get
Return DirectCast(Me.List(Me.List.Count - 1), Information)
End Get
End Property
End Class
Public Class CommentCollection
Inherits CollectionBase
Public Overloads Sub Add(ByVal Text As String)
Dim c As New Comment
c.Text = Text
List.Add(c)
End Sub
Default Public Property Item(ByVal index As Integer) As Comment
Set(ByVal Value As Comment)
Me.List(index) = Value
End Set
Get
Return DirectCast(Me.List(index), Comment)
End Get
End Property
End Class


Thanks
GeneralRe: Parse a text file into an object Pin
SomeGuyThatIsMe28-Aug-06 10:09
SomeGuyThatIsMe28-Aug-06 10:09 
GeneralRe: Parse a text file into an object Pin
AndyHug30-Aug-06 4:31
AndyHug30-Aug-06 4:31 
GeneralRe: Parse a text file into an object Pin
SomeGuyThatIsMe30-Aug-06 5:02
SomeGuyThatIsMe30-Aug-06 5:02 
QuestionProgress Bar: File Copy Pin
numbers1thru928-Aug-06 8:13
numbers1thru928-Aug-06 8:13 
AnswerRe: Progress Bar: File Copy Pin
pasha2k28-Aug-06 8:31
pasha2k28-Aug-06 8:31 
AnswerRe: Progress Bar: File Copy Pin
mav.northwind28-Aug-06 8:32
mav.northwind28-Aug-06 8:32 
GeneralRe: Progress Bar: File Copy Pin
pasha2k28-Aug-06 8:57
pasha2k28-Aug-06 8:57 
GeneralRe: Progress Bar: File Copy Pin
mav.northwind28-Aug-06 9:30
mav.northwind28-Aug-06 9:30 
AnswerRe: Progress Bar: File Copy Pin
Nader Elshehabi28-Aug-06 8:35
Nader Elshehabi28-Aug-06 8:35 
GeneralRe: Progress Bar: File Copy Pin
pasha2k28-Aug-06 8:51
pasha2k28-Aug-06 8:51 
GeneralRe: Progress Bar: File Copy Pin
Nader Elshehabi28-Aug-06 9:54
Nader Elshehabi28-Aug-06 9:54 
GeneralRe: Progress Bar: File Copy Pin
numbers1thru928-Aug-06 9:47
numbers1thru928-Aug-06 9:47 
QuestionDatagridViewCaption? Pin
Itanium28-Aug-06 7:07
Itanium28-Aug-06 7:07 
AnswerRe: DatagridViewCaption? Pin
Nader Elshehabi28-Aug-06 7:43
Nader Elshehabi28-Aug-06 7:43 
QuestionHttpWebRequest from c# app Pin
SomeGuyThatIsMe28-Aug-06 6:41
SomeGuyThatIsMe28-Aug-06 6:41 
QuestionKeycode Error on Crystal Report Pin
paulcortez28-Aug-06 6:29
paulcortez28-Aug-06 6:29 
QuestionDataViewManager Pin
~~~Johnny~~~28-Aug-06 6:17
~~~Johnny~~~28-Aug-06 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.