I have an issue while I am trying to read columns from a database and then write them with VB in a file. I want to have as end of each line the CR LF but some users in data entry added CR LF inside some columns (not know which of them). I want inside VB to remove all the CR LF except the one at the end of the row I am reading.
Asked
Active
Viewed 120 times
1
-
So what's stopping you? There are literally hundreds of existing questions about finding and replacing text in VB.Net, any one of which should get you started. – Ken White Apr 05 '17 at 12:51
-
Maybe you want to write a csv file. Try to enclose the string you want to write with chr(34). – muffi Apr 05 '17 at 12:51
-
in my current script I am reading a line from sql until I find CR LF, then I am changing row in my .txt file. The CR LF is supposed to be in the end of each line and not in columns.. The issue is to change the CR LF inside the columns and not the one at then end of the line.. – cgxanth Apr 05 '17 at 13:00
-
Anyone ? Still looking into it.. – cgxanth Apr 06 '17 at 08:09
1 Answers
0
I would replace the chars in your query, so you won't have to handle it in your VB Code. Some VB-Coders will maybe disagree ;-)
You tagged "tsql" so I wrote the code for a sql-server database:
DECLARE @row varchar(250)
SET @Row = 'Line'+CHAR(13)+'Break'
PRINT @Row
/* following will be printed:
Line
Break
*/
PRINT REPLACE(@Row,CHAR(13),'') + CHAR(13)
/*Will Print LineBreak + an CR LF at the end
You Could use it to Query your Data, so you won't have to replace it in your VB Code,
just use the replace-code in your SELECT:
SELECT REPLACE(@Row,CHAR(13),'') + CHAR(13)
*/
To replace it in VB: Replace line feed (LF) characters in a String using VB.NET

tgr
- 244
- 1
- 9
-
For further TSQL-Replacements, take a look at this post: https://stackoverflow.com/questions/31057/how-to-insert-a-line-break-in-a-sql-server-varchar-nvarchar-string – tgr Aug 04 '17 at 09:49