Welcome to WebmasterWorld Guest from 54.227.157.163

Forum Moderators: ocean10000

Message Too Old, No Replies

VB Script - Strip Carriage Returns

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

New User

10+ Year Member

joined:Dec 22, 2003
posts: 1
votes: 0


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.

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

Junior Member

10+ Year Member

joined:May 10, 2003
posts:58
votes: 0


Try this (not tested)

ExtractCR = Replace(stemp,VbCrlf,"")

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

Junior Member

10+ Year Member

joined:June 8, 2007
posts:76
votes: 0


i.e.

Function ExtractCR(stemp As String) As String

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

Probably want to replace with a space