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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to remove Carriage Returns

Status
Not open for further replies.

itmasterw

Programmer
Apr 13, 2003
147
US
Hi I have been asked to go through a text file an remove certian Carriage Returns througout the text.
For example, they certian lines have something like .00
P5471-161 in it, and the two squarses, which repersents the two squares, which represents; and they want the two of these removed. I have no trouble bringing in the file and finding lines with the p5471-61 in it, but I cannot find away to remove the Carriage Returns. I have tried something like the following:
If InStr(1, line, "P5471") = True Then
If InStr(1, line, Asc(13)) Then
line = Replace(line, Asc(13), "")
End If
End If
But this only seems to remove one Carriage Return and move the line down.
If anyone has any ideas hear I would appreciate it.
 
The 2 squares are often CR and LF. There is a VB constant vbCRLF which equates to the CR and LF combination. Try:

line = Replace(line, vbCRLF, "")

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thnk you for your quick responces, but unfortunantly this did not wor either; and yes thee two squares are the cariage returns that I am trying to get rid of. If you have any other ideas onm this please let me know.
 
have you checked exactly what the characters are? Loop through the line and do a Debug.Print of the ASCII value of each character

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
I could not get the debubug print ASCII out but, they are sure that these are a carage return and a line feed.
 


Your first if statement is not going to produce the results you want.

InStr returns an integer that is where in the string the substring is found. True is translated to -1. So you will probably not get inside that if statement and will not get to the replace statement.

I would suggest using:

If InStr(1, line, "P5471") Then

OR

If InStr(1, line, "P5471") <> 0 Then

-Sean
 
Sean,
I believe that testing integers for True/False will produce True for any non-zero value.

Just try this in Immediate window:

If 0 then ?"true" else ? "false"

which will produce 'false'

Then

If 1 then ?"true" else ? "false"

which will produce 'true'

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
John,

What you say is correct but when used in the following statment it does a numeric (not boolean) comparison where True is treated as -1:

If InStr(1, line, "P5471") = True Then

To check my point try the following code:
Code:
   Dim sInput As String: sInput = "Check this message"
   Dim sCheck As String: sCheck = "message"
   
   Dim sNumericResults As String
   Dim sBoolResults As String
   
   If InStr(1, sInput, sCheck) <> 0 Then
      sNumericResults = "Pass"
   Else
      sNumericResults = "Fail"
   End If
   
   If InStr(1, sInput, sCheck) = True Then
      sBoolResults = "Pass"
   Else
      sBoolResults = "Fail"
   End If
   
   Debug.Print "Numeric compairison: " & sNumericResults & vbCrLf & _
               "Boolean compairison: " & sBoolResults

RESULTS:

Numeric compairison: Pass
Boolean compairison: Fail


-Sean
 
Agreed. I was (probably unnecessarily) expanding on your :
<If InStr(1, line, "P5471") Then>

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top