Android Question Remove TAB

stratus

Active Member
Licensed User
Longtime User
I have a string with multiple tabs and i want to remove all tabs.
I try string.rplace(TAB,"") and string.replace (chr(9),"") without luck.Any suggestion?
 

Cableguy

Expert
Licensed User
Longtime User
How about treating them as a series of spaces?
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
Seem to work here (b4J)

upload_2016-9-29_12-29-45.png



Are you sure the original string has TAB's characters o simply many spaces?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Have you tried to open the file with ASCII encoding just to check for those TABs?
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
I've found again TABs with this code (in B4J) in your file (greece.txt); another option should be using jsoup library for scrapping the html file (http://stackoverflow.com/questions/24772828/how-to-parse-html-table-using-jsoup)

upload_2016-9-29_13-24-1.png


B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private fc As FileChooser
    Private str,strdir,strfile As String
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
   
    fc.Initialize
    fc.InitialDirectory="C:\Users\inaki\Downloads"
   
    Dim str As String=fc.ShowOpen(MainForm)
    strdir=str.SubString2(0,str.LastIndexOf("\"))
    strfile=str.SubString2(str.LastIndexOf("\")+1,str.Length)
    str=File.ReadString(strdir,strfile )
    findtabs(str)
   
End Sub

Sub findtabs (tabwstr As String)
    Log ($"${strfile} contains TABS = ${tabwstr.Contains(TAB)}"$)
    Log (str.Replace(TAB,","))
   
End Sub
 
Upvote 0

stratus

Active Member
Licensed User
Longtime User
This is the code i use
B4X:
Dim pos,pos1,pos2 As Int
Dim temptxt As String
temptxt=File.ReadString(File.DirInternal,"greece" & "2016")
pos=temptxt.IndexOf("Public holiday type")
temptxt=temptxt.SubString(pos+"Public holiday type".Length)
  
pos1=temptxt.IndexOf("<")
Do While pos1>-1
     pos2=temptxt.IndexOf2(">",pos1+1)
     stringInside=temptxt.SubString2(pos1+1,pos2)
     temptxt=temptxt.Replace("<" & stringInside & ">","")    
     pos1=temptxt.IndexOf("<")
Loop

temptxt=temptxt.replace(TAB,"") 'This is not working
 
Last edited:
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
With Jsoup you can save the Html elements/tags in lists: lstyears (years on HtmlPage), lstheaders (headers of each table), lsttabledata(data of each table). Attached code (B4J):

B4X:
#Region Project Attributes 
    #MainFormWidth: 10
    #MainFormHeight: 10
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private fc As FileChooser
    Private str,strdir,strfile,jsoupstr As String
    Private jsoup1 As jSoup
    Public lsttables,lstyears,lstheaders(20),lsttabledata(20) As List
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
   
    lsttables.Initialize
    lstyears.Initialize
   
    fc.Initialize
    fc.InitialDirectory="C:\Users\inaki\Downloads"
   
    Dim str =fc.ShowOpen(MainForm)
   
    If Not(str.Contains("\")) Then Return
   
    strdir=str.SubString2(0,str.LastIndexOf("\"))
    strfile=str.SubString2(str.LastIndexOf("\")+1,str.Length)
    str=File.ReadString(strdir,strfile )
   
    jsoupstr=jsoup1.parse_HTML(str)
   
    'Find years
    lstyears=jsoup1.getElementsByTag(str,"h2")
    For i=0 To lstyears.size-1
        Dim strtmp1 As String
        strtmp1=lstyears.get(i)
        strtmp1=strtmp1.SubString2(strtmp1.IndexOf(">")+1,strtmp1.LastIndexOf("<"))
        Log(strtmp1)
    Next
   
    'Find tables
    lsttables=jsoup1.getElementsByTag(str,"table")
    Dim strtmp(lsttables.Size) As String
   
    For i=0 To lsttables.Size-1
        strtmp(i)=lsttables.Get(i)
    Next
   
    'Find table headers
    For i=0 To strtmp.Length-1
        Dim lsttmp As List
        lsttmp.Initialize
        lsttmp=jsoup1.getElementsBytag(strtmp(i),"th")
        For j=0 To lsttmp.Size-1
            Dim strtmp1 As String
            lstheaders(i).Initialize
           
            strtmp1=lsttmp.get(j)
            strtmp1=strtmp1.SubString2(strtmp1.IndexOf(">")+1,strtmp1.LastIndexOf("<"))
            Log(strtmp1)
            lstheaders(i).Add(lsttmp.get(j))
            'Log(lsttmp.Get(j))
        Next       
    Next
   
    'Find table data
    For i=0 To strtmp.Length-1
        Dim lsttmp As List
        lsttmp.Initialize
        lsttmp=jsoup1.getElementsBytag(strtmp(i),"td")
        For j=0 To lsttmp.Size-1
            Dim strtmp1 As String
            lsttabledata(i).Initialize
           
            strtmp1=lsttmp.get(j)
            strtmp1=strtmp1.SubString2(strtmp1.IndexOf(">")+1,strtmp1.LastIndexOf("<"))
           
            lsttabledata(i).Add(strtmp1)
            Log(strtmp1)
        Next       
    Next
   
End Sub
 
Upvote 0
Top