Results 1 to 10 of 10

Thread: [RESOLVED] Remove non-tabed text from string

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Resolved [RESOLVED] Remove non-tabed text from string

    Hello.
    I have a question:
    I would like to know how should I remove the lines from this string, that don't start with the '<' marker and have not a tab on the begin of the line.
    (remove QZAIA, MFLA, MAI1 and MAW, in this case)

    Code:
    <ACCOUNT>
    	<ID>15315
    	<DATA_IN>2003-01-31 
    	<NAME>JS Uni
    	<CAS>0
    	<FAX>229
    	<FACT>Zi I - Sector VIII
    	<CIFACT>MUNDE
    	<STAFACT>Port
    	<CP>4471
    QZAIA
    MFLA
    	<WWW>
    	<TICKER>15315
    	<CPENTRG>447
    MAI1
    MAW
    	<ENTRG>6
    	<USER>
    </ACCOUNT>
    Thank you in advance for the advice.

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Remove non-tabed text from string

    Is that strng located in a Text File?

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Remove non-tabed text from string

    it can be.
    i'm reading this data from a database to export to a file.
    what happens here is a bug that i can't figure out why is it happening.
    So, before writing this string in a text file, i must remove those "alien" strings.

    thank you

  4. #4

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Remove non-tabed text from string

    ok, i've tried this but it gives me an error 5

    Code:
    Public Function DelAlienLines(Reg As String) As String
    
    Dim ExisteQuebra As Long, existequebra2 As Long, PosStr As String, Tmnh As Long, ExisteTab As Long, ExisteHead As Long
    Dim tmpstr1 As String, tmpstr2 As String
    PosStr = 0
    
    
    Tmnh = Len(Reg)
    
    
    While PosStr < Tmnh
        ExisteQuebra = InStr(PosStr, Chr(13), Reg
        If ExisteQuebra >= 0 Then
            ExisteTab = InStr(PosStr, vbTab, Reg)
            If ExisteTab >= 0 Then 
                ExisteHead = InStr(PosStr + 1, "<", Reg)
                If ExisteHead >= 0 Then
                    existequebra2 = InStr(ExisteHead + 1, Chr(13), Reg) 
    
                    tmpstr1 = Left(Reg, ExisteQuebra)
                    tmpstr2 = Right(Reg, existequebra2)
                    DelAlienLines = tmpstr1 & tmpstr2
                End If
            End If
        End If
    
    PosStr = PosStr + 1
    Wend
    
    End Function
    Help needed

  5. #5
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Remove non-tabed text from string

    This code wil help you to identify the lines you dont want.

    Past those text in to a text file and place it in the path shown. then execute thsi code

    Code:
    Private Sub Command1_Click()
    Dim line As String
    Dim fno As Long
    
    fno = FreeFile()
    Open "c:\temp\test.txt" For Input As #fno
    
    Do While Not EOF(fno)
        Line Input #fno, line
        If Left(line, 1) <> "<" And Left(line, 1) <> vbTab Then
           MsgBox line
        End If
    Loop
    close(fno)
    End Sub
    Last edited by Fazi; Sep 24th, 2007 at 11:58 AM.

  6. #6

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Remove non-tabed text from string

    I haven't yet tested your code, but i belive it works well, but I do not want to use another file. Can u please see my code?
    I must treat this bug before writing the text file.
    What I send to my function is that kind of xml in string format.

    Thank you.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Remove non-tabed text from string

    InStr(ExisteHead + 1, Chr(13), Reg)
    should be
    InStr(ExisteHead + 1, Reg, Chr(13))
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Remove non-tabed text from string

    I've tested with your correction. it give me no error but still doesn't work very well.

    need more help please.

  9. #9
    Addicted Member Vanasha's Avatar
    Join Date
    Jun 2007
    Location
    In a bin.>_>
    Posts
    152

    Re: Remove non-tabed text from string

    Quote Originally Posted by RS_Arm
    I've tested with your correction. it give me no error but still doesn't work very well.

    need more help please.
    I've made an example too, i'm not totally sure if it will suit your needs.
    Code:
    Dim Data() As String: Dim i As Integer: Dim Res As String
    Open App.Path & "\Test.txt" For Input As #1
        Data() = Split(Input(LOF(1), 1), vbCrLf)
    Close #1
    For i = 0 To UBound(Data())
        If (Left(Data(i), 1) = vbTab Or Left(Replace(Data(i), vbTab, ""), 1) = "<") Then
                Res = Res & Data(i) & vbNewLine
        End If
    Next i
    MsgBox Res 'This is the finished string
    Quote Originally Posted by Vanasha
    Sorry, i'm slow.


  10. #10

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [RESOLVED] Remove non-tabed text from string

    I've been re-writing from scratch the export function so it could do a replace to all chr(13) and chr(10) with no header from my datafields.
    Thank you all anyway for the help.
    Really appreciated.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width