Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
CR LF problem
I am using a user defined function, ReadTextFile(), to read
the contents of a text file into a string variable. The basic code looks like this: Dim s as string s = ReadTextFile("C:\data.txt") Now that the entire text file is stored in a string variable, I would like to replace occurences of multiple carriage returns (CR) or line feeds (LF) with a single carriage return. In other words, I want all paragraphs to be single-spaced, with only one CR and/or LF between paragraphs. Finally, I need to write that single-space string to a new file, and preserve the single-spaced format in the new file. The biggest problem here, is that my text files come from various sources, and each source uses different byte representations of "carriage returns". I have noticed in some files that a line break is represented by one CR (or character 13 or hex "0D")....other files use CR-CR-LF (or 13-13-10 or hex "0D-0D-0A") to represent a line break. I think some files only use CR-LF ("0D-0A"), etc.... Does anyone know any good algorithms or functions that can help replace any sequence of combinations of CR and/or LF with just one CR LF line break? Thank you '------------------------------------------------- ' BTW, here is the ReadTextFile() function again: Public Function ReadTextFile$(Filename$) ' Reads large amounts of data from a text file in one single step. Dim iNum% On Error GoTo ErrHandler iNum = FreeFile(): Open Filename For Input As #iNum ReadTextFile = Space$(LOF(iNum)) ReadTextFile = Input(LOF(iNum), iNum) ErrHandler: Close #iNum: If Err Then Err.Raise Err.Number, , Err.Description End Function 'ReadTextFile() |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
CR LF problem (BTW)
I forgot to mention..... I would like all line break characters
to be the same throughout the entire string. Using CRLF or vbCrLf will be fine. Or, just one CR is good. As long as it's consistent all throughout the string. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
CR LF problem (BTW)
I forgot to mention..... I would like all line break characters
to be the same throughout the entire string. Using CRLF or vbCrLf will be fine. Or, just one CR is good. As long as it's consistent all throughout the string. Ok, so if you say there are possibly 2 cr characters together, but only 1 LF character regardless of how many Cr chars, then... 'delete all CRs s = Replace(s, vbCr, "") 'replace all LFs with CRLFs s = Replace(s, vbLf, vbCrLf) OR s = Replace(Replace(s, vbCr, ""), vbLf, vbCrLf) -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel startup problem. Possible problem with stdole32.tlb | Excel Programming | |||
Colon at the end of excel file name(ex: problem.xls:1, problem.xls | New Users to Excel | |||
Started out as an Access problem. Now an Excel problem | Excel Discussion (Misc queries) | |||
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? | Excel Programming |