I am trying to write a function for determining the data type of columns in a delimited file.
However my function is not detecting a newline and exiting the loop after the end of the first line.
* 'del_2' is equal to a new line character, i have tested this using a small bit of code
and got the message, and i know the newline characters are at the end of each line in 'filecontents' as i am adding them manually.
Thanks for any help, Alex.
However my function is not detecting a newline and exiting the loop after the end of the first line.
* 'del_2' is equal to a new line character, i have tested this using a small bit of code
Code:
if del_2 = ControlChars.NewLine then MessageBox.Show("It is a newline") end if
Code:
Public Shared Function DetermineColumns(ByVal filepath As String, ByVal delimiters As KeyValuePair(Of String, String)) As List(Of KeyValuePair(Of String, Type)) Dim result As New List(Of KeyValuePair(Of String, Type)) Dim reader As New StreamReader(filepath) Dim filecontents As String = "" While reader.EndOfStream() = False filecontents = filecontents & reader.ReadLine() & ControlChars.NewLine End While reader.Close() reader.Dispose() Dim del_1 = delimiters.Key, del_2 As String = delimiters.Value Dim read As String = "" For i As Integer = 0 To (filecontents.Length - 1) Step 1 Dim curr_char As String = filecontents(i) If curr_char <> del_1 And curr_char <> del_2 Then read = read & curr_char Else If curr_char = del_1 Then result.Add(New KeyValuePair(Of String, Type)(String.Format("{0}_{1}", DetermineDataType(read).Name, i.ToString()), DetermineDataType(read))) read = "" End If If curr_char = del_2 Then Exit For End If End If Next Return result End Function
Comment