Forum Moderators: open

Message Too Old, No Replies

VB Script - Strip Carriage Returns

         

redknights11

2:53 am on Feb 19, 2008 (gmt 0)

10+ Year Member



OK, I am somewhat of a newbie, but I need your help. I am trying to import data into a SQL table using VB, but I can't get it to strip out carriage returns (there may be more than one in the string) before importing the text. This is what I have so far:


Function ExtractCR(stemp As String) As String
Dim lPosofEnterinText As Long
Dim stemp1 As String
'---------------------- Look for a carriage return in the Text
lPosofEnterinText = InStr(1, stemp, Chr(10), vbTextCompare)
If lPosofEnterinText <> 0 Then
stemp = Mid$(stemp, 1, lPosofEnterinText - 1)
End If
lPosofEnterinText = InStr(1, stemp, Chr(13), vbTextCompare)
If lPosofEnterinText <> 0 Then
stemp = Mid$(stemp, 1, lPosofEnterinText - 1)
End If

ExtractCR = stemp
End Function

What am I doing wrong? Can anyone help?

Thanks.

makeupalley

6:29 am on Feb 19, 2008 (gmt 0)

10+ Year Member



Try this (not tested)

ExtractCR = Replace(stemp,VbCrlf,"")

Monkey

7:47 pm on Feb 26, 2008 (gmt 0)

10+ Year Member



i.e.

Function ExtractCR(stemp As String) As String

ExtractCR = Replace(stemp,VbCrlf," ")
End Function

Probably want to replace with a space