Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s1 = vbCrLf & "abc"
- s2 = "ab" & vbCrLf & "c"
- MsgBox "---" & IIf(Left(s1, 2) = vbCrLf, Replace(s1, vbCrLf, "", , 1), s1)
- MsgBox "---" & IIf(Left(s2, 2) = vbCrLf, Replace(s2, vbCrLf, "", , 1), s2)
- If Len(string) > 0 Then
- Do While Left(string,1)= chr(13) Or Left(string,1)= chr(10) or Left(string,1) = " "
- string = Right(string, len(string)-1)
- Loop
- End If
- Public Function trimCrOrLf(ByVal s As String) As String
- Dim firstChar As String
- firstChar = Left(s, 1)
- Do While InStr(vbCr & vbLf, firstChar) > 0
- s = Mid(s, 2)
- firstChar = Left(s, 1)
- Loop
- trimCrOrLf = s
- End Function
- UPDATE MyTable SET MyTable.memo_field = Mid([memo_field],3)
- WHERE (((MyTable.memo_field) Like Chr(13) & Chr(10) & "*"));
- Private Sub TestLineFeed()
- Dim strString$, strTestChar, booStartsWith_CR As Boolean
- strString = Chr$(13) & "some text"
- strTestChar = "2"
- 'strTestChar = Chr$(13) ''This is a CR.
- booStartsWith_CR = (Left(strString, 1) = strTestChar)
- Debug.Print "-----"
- Debug.Print "Raw: " & strString
- Debug.Print booStartsWith_CR
- If booStartsWith_CR Then
- strString = Mid(strString, 2, 100)
- End If
- Debug.Print "-----"
- Debug.Print "New: " & strString
- End Sub
- Function LTrimCRLF(s As String) As String
- Dim index As Integer, start As Integer, strLen As Integer
- Dim c As String
- strLen = Len(s)
- index = 1
- start = -1
- Do While (index <= strLen) And (start = -1)
- c = Mid(s, index, 1)
- If (c = vbCr) Or (c = vbLf) Then
- index = index + 1
- Else
- start = index
- End If
- Loop
- If start = -1 Then
- LTrimCRLF = ""
- Else
- LTrimCRLF = Mid(s, start)
- End If
- End Function
- Sub TestLTrimCRLF()
- Dim withWS As String, noWS As String, blank As String, onlyWS As String
- withWS = vbCrLf & " this string has leading white space"
- noWS = "this string has no leading white space"
- onlyWS = vbCrLf & " " & vbCrLf & " "
- blank = ""
- Say "with WS: {" & LTrimCRLF(withWS) & "}"
- Say "no WS: {" & LTrimCRLF(noWS) & "}"
- Say "only WS: {" & LTrimCRLF(onlyWS) & "}"
- Say "blank: {" & LTrimCRLF(blank) & "}"
- End Sub
- Function trimWhitespace(str As String) As String
- Dim idx As Long
- Dim ch As String
- If Len(str) > 0 Then
- idx = 1
- ch = Mid(str, idx, 1)
- Do While ch = Chr(13) Or ch = Chr(10) Or ch = " "
- idx = idx + 1
- ch = Mid(str, idx, 1)
- Loop
- If (idx > 1) Then str = Right(str, Len(str) - idx)
- End If
- idx = Len(str)
- If idx > 0 Then
- ch = Mid(str, idx, 1)
- Do While ch = Chr(13) Or ch = Chr(10) Or ch = " "
- idx = idx - 1
- ch = Mid(str, idx, 1)
- Loop
- If (idx < Len(str)) Then str = Left(str, idx)
- End If
- trimWhitespace = str
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement