Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hidden white space characters? 1

Status
Not open for further replies.

PureSoft

Programmer
Aug 12, 2002
24
0
0
GB
Hi,

I have a csv export file (from a shopping cart system) that when processed raw, gives problems because the end of line character does not appear to be right. It will view fine in Excel, starting new lines as supposed to, its just that when I use the 'Line Input' command on the raw file it doesn't seem to detect the end of lines properly. When I look at the raw file in Notepad there is a square symbol there at the end of each line.

However if I now save that file in Excel with in the csv format, the file now processes fine and when I look at the file in notepad there is no square character there at the end of the line, so it must be substituted with a different and better white space character.

How can I pre-process the file myself to exchange those white space characters to suitable ones. What character codes should I use and how do I inspect what the actrual whitespace character values are?

Thanks for your help.

Philip.
 
I would open the file in a hex editor and see what characters are there then do a replace with the replace function.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Hi,

I'm really not getting anywhere :-( I can't seem to open the file read through it and replace the characters as required. I used ultraedit to view the files and see its because I don't have the carriage return character in my csv, just the line feed, that's tripping my routines up, so I wamt to add the chr(13) infront of any chr(10) detected. I did a search and replace with ultraedit and verified this fixes the file for me, so its getting it accomplished in VB that I need to do.

to summarise, I want to search through a file for chr(10) and replace this occurrence with the following 2 characters chr(13) & chr(10).

I keep getting errors further down my routines when I try to access the file again - I think I must be accessing it wrong. Could anybody supply example code of how this is done, I think I must need some binary access and modifying, but I'm confused.

Thanks, for your help.

Philip.
 

Something like...
[tt]
Dim FNumb As Integer, FName As String
Dim S As String

FNumb = FreeFile
FName = "Your path file name"

'opne the file, retrieve the contents, close the file
Open FName For Binary As #FNumb
S = Input(FileLen(FName), #FNumb)
Close #FNumb

'replace
S = Replace(S, vbLf, vbNewLine)

FNumb = FreeFile

'write over the file with the new contents
Open FName For Output As #FNumb
Print #FNumb, S
Close #FNumb
[/tt]

Good Luck

 
vb5prgrmr,

Thanks so much - I was trying something along those lines, but was getting muddled how to structure things properly. I ran the code and had to add just one extra line under the replace line of code section of

S = Left(S, (Len(S) - 2)) to chop off an extrs vbNewLine character that it seemed to add (maybe because the pointer was not incremented past the eof, but the last replace shifted in an extra chr(10), which was detected and replace again. Anyway, the file is fixed and now I can move on with the rest of my code.

Cheers, Philip.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top