Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing double "newline" strokes from string

Status
Not open for further replies.

parkesto

Programmer
May 23, 2013
3
0
0
CA
Hi all,

I am having issues properly identifying the end of a string I am parsing into an array because of multiple new line strokes. I am properly identifying it ending on a "space" and not mid word, but because of the Chr$(10) check I have when it hits a double enter it assumes the note has finished.

I figured the easiest way around this is using a custom function ->

Code:
Function RemoveChars(strText As String, strUnwanted As String) As String

    Dim TempStr, CurChar As String
    Dim x As Integer
    
    For x = 1 To Len(strText)
        CurChar = Mid(strText, x, 1)
        If InStr(strUnwanted, CurChar) = 0 Then TempStr = TempStr & CurChar
    Next x
    RemoveChars = TempStr
    
End Function

To remove it, but it appears in the CSV the enter strokes are registered as Chr$10, not Chr$13 for carriage return, so I'm having a brutal time clearing them out. Here's where it's doing the work of storing the lines of the string into an array (no more than 64 chars per entry).

Any help would be super appreciated, it's been bugging me a while.

Code:
While GetField(sInput,sNoteArrayCnt+1, Chr$(10)) <> ""
            Redim Preserve sNoteArray(sNoteArrayCnt)
            sNoteArray(sNoteArrayCnt) = GetField$(sInput,sNoteArrayCnt+1, Chr$(10))
            sNoteArrayCnt = sNoteArrayCnt + 1
        Wend
    
        k=0
        ReDim fNoteArray(0)
         
            For i = LBound(sNoteArray) To UBound(sNoteArray)
                arrayItem = sNoteArray(i)
                Do While (Len(arrayItem)>0)
                    temp = Left$(arrayItem,64)
                    If(Trim$(Right$(temp,1)) = "" Or Trim$(Mid$(arrayItem,64,1))="") Then
                        If(k<>0) Then
                            ReDim Preserve fNoteArray(UBound(fNoteArray) + 1)
                        End If 
                        fNoteArray(UBound(fNoteArray)) = RTrim$(temp)
                        arrayItem = Trim$(Mid$(arrayItem, 64))
                        k = k + 1
                    Else
                        trimLength = 0
                        Do While(Mid$(temp,len(temp)-trimlength,1) <> " ")
                            trimLength = trimLength + 1                    
                        Loop

                        temp = Mid$(temp, 1, Len(temp) - trimLength - 1)
                        If (k <> 0) Then
                            ReDim Preserve fNoteArray(UBound(fNoteArray) + 1)
                        End If
                        fNoteArray(UBound(fNoteArray)) = RTrim$(temp)
                        arrayItem = trim$(Mid$(arrayItem, Len(temp)+1))
                        k = k + 1
                    End If
                Loop   
            Next
        
        For x = 0 To UBound(fNoteArray)
             FixedNote = fNoteArray(x)
             FixedNote = RemoveChars(FixedNote, Chr$(9))
             FixedNote = LTRIM(FixedNote)
             Print #2, FixedNote
        Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top