Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. s1 = vbCrLf & "abc"
  2. s2 = "ab" & vbCrLf & "c"
  3.  
  4. MsgBox "---" & IIf(Left(s1, 2) = vbCrLf, Replace(s1, vbCrLf, "", , 1), s1)
  5. MsgBox "---" & IIf(Left(s2, 2) = vbCrLf, Replace(s2, vbCrLf, "", , 1), s2)
  6.  
  7. If Len(string) > 0 Then
  8. Do While Left(string,1)= chr(13) Or Left(string,1)= chr(10) or Left(string,1) = " "
  9. string = Right(string, len(string)-1)
  10. Loop
  11. End If
  12.  
  13. Public Function trimCrOrLf(ByVal s As String) As String
  14. Dim firstChar As String
  15.  
  16. firstChar = Left(s, 1)
  17. Do While InStr(vbCr & vbLf, firstChar) > 0
  18. s = Mid(s, 2)
  19. firstChar = Left(s, 1)
  20. Loop
  21. trimCrOrLf = s
  22. End Function
  23.  
  24. UPDATE MyTable SET MyTable.memo_field = Mid([memo_field],3)
  25. WHERE (((MyTable.memo_field) Like Chr(13) & Chr(10) & "*"));
  26.  
  27. Private Sub TestLineFeed()
  28. Dim strString$, strTestChar, booStartsWith_CR As Boolean
  29.  
  30. strString = Chr$(13) & "some text"
  31.  
  32. strTestChar = "2"
  33. 'strTestChar = Chr$(13) ''This is a CR.
  34.  
  35. booStartsWith_CR = (Left(strString, 1) = strTestChar)
  36.  
  37. Debug.Print "-----"
  38. Debug.Print "Raw: " & strString
  39. Debug.Print booStartsWith_CR
  40.  
  41. If booStartsWith_CR Then
  42. strString = Mid(strString, 2, 100)
  43. End If
  44.  
  45. Debug.Print "-----"
  46. Debug.Print "New: " & strString
  47. End Sub
  48.  
  49. Function LTrimCRLF(s As String) As String
  50. Dim index As Integer, start As Integer, strLen As Integer
  51. Dim c As String
  52.  
  53. strLen = Len(s)
  54. index = 1
  55. start = -1
  56.  
  57. Do While (index <= strLen) And (start = -1)
  58. c = Mid(s, index, 1)
  59.  
  60. If (c = vbCr) Or (c = vbLf) Then
  61. index = index + 1
  62. Else
  63. start = index
  64. End If
  65. Loop
  66.  
  67. If start = -1 Then
  68. LTrimCRLF = ""
  69. Else
  70. LTrimCRLF = Mid(s, start)
  71. End If
  72. End Function
  73.  
  74. Sub TestLTrimCRLF()
  75. Dim withWS As String, noWS As String, blank As String, onlyWS As String
  76.  
  77. withWS = vbCrLf & " this string has leading white space"
  78. noWS = "this string has no leading white space"
  79. onlyWS = vbCrLf & " " & vbCrLf & " "
  80. blank = ""
  81.  
  82. Say "with WS: {" & LTrimCRLF(withWS) & "}"
  83. Say "no WS: {" & LTrimCRLF(noWS) & "}"
  84. Say "only WS: {" & LTrimCRLF(onlyWS) & "}"
  85. Say "blank: {" & LTrimCRLF(blank) & "}"
  86. End Sub
  87.  
  88. Function trimWhitespace(str As String) As String
  89. Dim idx As Long
  90. Dim ch As String
  91. If Len(str) > 0 Then
  92. idx = 1
  93. ch = Mid(str, idx, 1)
  94. Do While ch = Chr(13) Or ch = Chr(10) Or ch = " "
  95. idx = idx + 1
  96. ch = Mid(str, idx, 1)
  97. Loop
  98. If (idx > 1) Then str = Right(str, Len(str) - idx)
  99. End If
  100.  
  101. idx = Len(str)
  102. If idx > 0 Then
  103. ch = Mid(str, idx, 1)
  104. Do While ch = Chr(13) Or ch = Chr(10) Or ch = " "
  105. idx = idx - 1
  106. ch = Mid(str, idx, 1)
  107. Loop
  108. If (idx < Len(str)) Then str = Left(str, idx)
  109. End If
  110.  
  111. trimWhitespace = str
  112. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement