Removing blank line at end of string before writing to text file? - vb.net

Been searching around for this for a couple hours, can't find anything which will do this correctly. When writing a string to a text file, a blank line is outputted at the end.
writeString = New StreamWriter(path, False)
writeString.WriteLine("Hello World")
writeString.Flush()
writeString.Close()
This will write the following to file:
Hello World
(Blank Line)
I've tried removing last character of string (both as regular string with varString.Substring(0, varString.Length - 1) and also as a list of string with varList.RemoveAt(varList.Count - 1)) but it just removes the literal last character.
I've also tried using Replace(vbCrLf, "") and many variations of it but again, they only remove literal new lines created in the string, not the new line at the end that is magically created.
Preferably, I'm seeking a method which will be able to remove that magical newline before the string is ever written to the file. I found methods which read from the file and then write back to it which would require Write > Read > Write, but in all cases the magical new line still appeared. :(
If it's important to note: The file will contain a string which may contain actual new lines (it's 'Song Artist - Song Title', though can contain other information and new lines can be added if the user wishes). That text file is then read by other applications (such as mIRC etc) of which output the contents by various means depending on application.
Eg. If an application were to read it and output it into a textbox.. the new line will additionally output to that textbox.. which is a problem! I have no control of the applications which will read the file as input considering it's the client which decides the application, so the removal of the new line needs to be done when outputted.
Help is appreciated~!

Use the Write method instead of WriteLine. The WriteLine method is the one adding a blank 0 length line to the file because it is terminating the "Hello World" string with a newline.
writeString.Write("Hello World")

Related

Kotlin: Printing string with array elements that cuts off left side of answers

I am writing a small text based game to familiarize myself with Kotlin. I am creating two strings that print out the multiple choice options. I have confirmed that all four array elements are captured appropriately, but when the string prints it cuts off the a) and c) options. I have used \t, spaces, etc. and it does the same thing. I have also tried to just use print() and then use a \n at the end
println(menuList[0])
println(menuList[1])
println(menuList[2])
println(menuList[3])
println("a) ${menuList[0]} b) ${menuList[1]}")
println("c) ${menuList[2]} d) ${menuList[3]}")
Output:
erroneous output of multiple choice text
The source text came from a file which was separating each line with \r\n, but the code reading it was splitting it with \n. The result was that each entry ended with \r. When printed out, this caused the first value to be overwritten.
The solution is, when reading the file, to split by \r\n rather than \n.

Foreach loop filename

I am getting familiar with an SSIS solution and I just realized something that is new for me:
there is a foreach loop task which contains this information in the "Files:" box:
What does it mean?
Does it mean that the task will take the files with name like:
A(something)Sell(something)Depot(something).csv?
like: A10Sell123Depot21.csv
In the Files text box, The asterisk wildcard (*) mean that you don't know this part of the name.
`*` --> unknown string
`?` --> unknown character
Example:
"In the Files text box, enter File.txt. The asterisk wildcard () let’s us include any text file that starts with “File,” without having to specify each file. If our files had instead been Word files, we would have entered File.doc. If we were moving multiple file types, we would have used File*.* as our property value." Read More
So in your case, yes A*Sell*Depot*.csv means A(something)Sell(something)Depot(something).csv which will match A10Sell123Depot21.csv

Removing handling newlines in a simple text import class

I have an input file that I want to use the string SPLIT function on for each line, depending on the Type field. However, the description field sometimes has data that has new lines in it so it messes up my file reader since it uses streamreader's readline() function
Handled:
Type|Name|User|Description
Type|Name|User|Description
Unhandled:
Type|Name|User|Description line 1
Description Line 2
Type|Name|User|Description
Besides not being able to validate on 'Type' for each line and keep reading the file for when the next Type field appears, are there any ways folks can come up with to properly read this file?
My solution was to have the file maker replace newline characters in their description field with another unique character that I can later add back in. I'm still interested in solutions from the file reader's perspective though
I know I'm talking to myself a lot here, but I found another solution, which is to remove remove line feeds, since the output file creator wrote out carriage returns for each line.
You could easily set a conditional statement to see if the Split array contains more than one element, which would indicate that it's a line you want to parse.

Jython - Extract information

I try to programm in jython but I have some problems.
I would like to read information after the :
For the moment "Ext" only read the first line of the webpage and I don't know why.
This is the first problem.
Then I would like to do a while to read all the file.
When I did it, the while never finish.
how can I extract information after the :
Thanks for your help
You should read next line in while loop, for now you read only one line! That is main problem that causes your while loop is infinite loop!
What library do you use to read HTTP response? Your code is without any import
Is it working code? I don't know .Contains() method. In Python/Jython there is if ':' in Ext to check if char or sting is in other string
You can split line like: s1, s2 = Ext.split(':', 1), and then use s2 variable: it contains text after first : , then you can strip() it to remove spaces or other white chars at both ends of the string

Modify regex code, only one line

I have this code
Dim parts As New List(Of String)(Regex.Split(RichTextBox2.Text, "~\d"))
That splits lines in this format into parts:
~1Hello~2~3Bye~4~5Morning~6
So if I do MsgBox(parts(5)), it will show me "Morning".
I want to do the exact same thing, but now my line is arranged like this:
Hello, Bye, Morning,
Change "~\d" to ", ?". The question mark after the space means that the space is optional.
Alternatively, assuming that you are only looking for single words, instead of Regex.Split you could use Regex.Matches with the regular expression "\w+".