Short URL: http://vb6.info/kdaqc
This is a trim function that removes spaces AND optionally tabs from the left and/or right side of a string.
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
'////////////////////////// THIS IS A TRUE TRIM FUNCTION AS BOTH SPACES ///////////////////////////////////////////////// '///////////////////////// AND TABS ARE TRIMMED FROM THE STRING ////////////////////////////////////////////////////////// Function sfuncTrim(sSource As String, bLeft As Boolean, bRight As Boolean, Optional bTabsAlso As Boolean) As String On Error GoTo err: Dim sLine As String, sChr As String, sOut As String Dim i As Integer, iCnt As Integer: iCnt = 1 Dim sParts() As String: sParts = Split(sSource, vbCrLf) 'split [sSource] line by line Dim iUpp As Integer: iUpp = UBound(sParts) ' how many total lines in [sSource] For i = 0 To iUpp ' look at every line of [sSource] sLine = sParts(i) If bLeft Then 'we are trimming left Do sChr = Mid$(sLine, 1, 1) 'look at the first character of [sLine] If sChr = " " Then ' if it is a space remove it sLine = Mid$(sLine, 2) End If If bTabsAlso Then ' if we are also removing tabs... If sChr = vbTab Then ' if current, first, character is a tab..... sLine = Mid$(sLine, 2) 'remove that End If End If Loop Until sChr <> vbTab And sChr <> " " ' keep looping until the first character is not a tab or space End If If bRight Then 'if we are trimming right... Dim iLen As Integer Do iLen = Len(sLine) 'len of current line If iLen = 0 Then 'if the length of the line = 0 then no need to process further GoTo emptyline: End If sChr = Mid$(sLine, iLen, 1) 'get the last character of the line If sChr = " " Then 'if it is a space... sLine = Mid$(sLine, 1, (iLen - 1)) ' remove the last character End If If bTabsAlso Then 'we are removing tabs from the right If sChr = vbTab Then 'if the last character is a tab sLine = Mid$(sLine, 1, (iLen - 1)) 'remove it End If End If Loop Until sChr <> vbTab And sChr <> " " ' loop until the last character is not a space or tab End If If Len(sLine) > 0 Then ' if after trimming spaces and tabs there is anything left of the line add it to [sOut] sOut = (sOut & sLine & vbCrLf) End If emptyline: Next i sOut = strings.sfuncEndVBCRLFremoved(sOut) 'remove the last carriage return sfuncTrim = sOut Exit Function err: With err If .Number <> 0 Then ErrHandler.ReportError Date & ": [modulename].sfuncTrim." & Err.Number & "." & Err.Description Resume Next End If End With End Function |
Short URL: http://vb6.info/kdaqc
Pingback: Cıvata()