Short URL: http://vb6.info/gns1r
Remove ALL Carriage Returns from Beginning and End of a String in VB6
This simple function removes all carriage returns that are at the beginning and end of a string (based upon values of [bRemoveCRStart] and [bRemCRend])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
'----------------------------------------------------------------------------- 'Remove all trailing and leading carriage returns/line feeds '----------------------------------------------------------------------------- Function sfuncVBCRLFremoved(ByVal strSource As String, Optional bRemoveCRStart As Boolean = True, Optional bRemCRend As Boolean = True, Optional bTrimSource As Boolean = True) As String On Error GoTo err_h: Dim s As String Dim iLen As Integer If bRemoveCRStart Then testPointStart: 'get first two characters of string s = Mid$(strSource, 1, 2) If s = vbCrLf Then iLen = Len(strSource) 'len of [strSource] strSource = Mid(strSource, 3, (iLen - 2)) GoTo testPointStart: 'test first two characters End If End If If bRemCRend Then testPointEnd: 'get last two characters of string s = Mid$(strSource, Len(strSource) - 1, 2) 'if last two characters are carriage return and 'line feed then trim off the last 2 characters If s = vbCrLf Then iLen = Len(strSource) 'len of [strSource] strSource = Mid$(strSource, 1, (iLen - 2)) GoTo testPointEnd: 'test last two characters End If End If If bTrimSource Then strSource = Trim$(strSource) 'return with leading and trailing carriage returns removed sfuncVBCRLFremoved = strSource Exit Function err_h: With err If .Number <> 0 Then 'create .bas named [ErrHandler] see http://vb6.info/h764u ErrHandler.ReportError Date & ": sfuncVBCRLFremoved." & err.Number & "." & err.Description Resume Next End If End With End Function |
Short URL: http://vb6.info/gns1r