[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.
Re: Remove non-tabed text from string
Is that strng located in a Text File?
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
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 :confused:
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
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.
Re: Remove non-tabed text from string
InStr(ExisteHead + 1, Chr(13), Reg)
should be
InStr(ExisteHead + 1, Reg, Chr(13))
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.
:eek:
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.
:eek:
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
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.
:wave: