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 -
if del_2 = ControlChars.NewLine then
-
MessageBox.Show("It is a newline")
-
end if
-
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. - 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
Thanks for any help, Alex.
5 3095
Did you check the length of (filecontents.L ength - 1)? I'm guessing from your explaination it's 1...
Steven
Nah there are many newline characters before the end of the stream, and filecontents.Le ngth - 1 prevents an IndexOutofRange exception which i would get if i removed the - 1.
And i know the newline characters are there as i can use them to manipulate the string, such as filecontents.Sp lit(ControlChar s.NewLine) will split the string in the correct places.
My only explanation is the way i am reading characters one by one, im thinking new line characters are longer then one character?
Check your code between line 26 and 28. This is how I read it: Whenever it enters that If-clause, you exit the for...next-loop, which means that your function will end...Is that what you want?
Steven
yeah as soon as it hits the newline i want it to send, however the function doesn't end and this is the problem.
Thanks
So, why don't you add an Exit For to the part where the NewLine is intercepted?
Steven
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mudge |
last post by:
I'm having a problem getting rid of newlines.
say I have this situation:
$cat = "A nice\n cat";
The "\n" is an escape character which creates a newline right there.
Now, how would I get rid of the newline in that string?
|
by: Vamsi |
last post by:
Hi,
I am trying a basic opearation of splitting a multiline value to an
array of single lines(Actually making Address into AddressLine1,
AddressLine2).
I used Environment.NewLine in split, I could get only 1st line, but it
is not returning 2nd line.
here's code:
string address = null;
string ssep = Environment.NewLine;
char sep =...
|
by: Howard Kaikow |
last post by:
I have never seen WriteLine fail to produce a NewLine, at least, not until
now:
I was playing with an example given on pages 51-52 of the book "A Visual
Basic 6 Programmer's Toolkit".
The book is accompanied by files for that chapter in which an example uses
VB 6's Print to output to a Form..
When upgrading the code to VB .NET 2002, the...
|
by: Howard Kaikow |
last post by:
I have never seen WriteLine fail to produce a NewLine, at least, not until
now:
I was playing with an example given on pages 51-52 of the book "A Visual
Basic 6 Programmer's Toolkit".
The book is accompanied by files for that chapter in which an example uses
VB 6's Print to output to a Form..
When upgrading the code to VB .NET 2002, the...
|
by: Jm |
last post by:
Hi all
Is there a way to search a string and count the amount of newline or crlf's
that are inside it ? Under vb6 i could search for vbcrlf using Instr and a
loop. Is there a similar method under .net ?
| |
by: Peter Kirk |
last post by:
Hi
I would like to ask a little bit about the value Environment.Newline: what
is it and what is the point of it? Ok, I can see in the docs that it
represents "newline" for the current platform - I assume that it is a
runtime property, and not compile time?
But won't it always be the same anyway - does dotnet run on anything other
than...
|
by: Adam Right |
last post by:
Hi,
Is there a way to construct the mail body including newline characters by
using .net framework mailing functions when sending an email? I cannot
insert newline character into the body of the mail.
Thanks...
|
by: John Salerno |
last post by:
If I read a string that contains a newline character(s) into a variable,
then write that variable to a file, how can I retain those newline
characters so that the string remains on one line rather than spans
multiple lines?
Example: In a CGI script, I'm reading the address field from an HTML
form. Almost always the person will press ENTER...
|
by: linq936 |
last post by:
Hi,
I read in many places that the string to be outputted by printf()
must be ending with newline, for example, it should be
printf("Hello World.\n");
instead of
printf("Hello World.");
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |