How can i use Regex.Split

bishmedia

Member
Licensed User
Longtime User
How can i get say the first bit of the text file into the listview eg AB15 without the quotes.???

I believe i use something called Regex.Split

Code:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("csv_listview")
    Dim Reader As TextReader
       Reader.Initialize(File.OpenInput(File.DirAssets, "pc.csv"))
       Dim line As String
       line = Reader.ReadLine
      
      Do While line <> Null
          line = Reader.ReadLine         
          ListView1.AddSingleLine(line)
      Loop
      
End Sub
 

Attachments

  • listview.jpg
    listview.jpg
    61.7 KB · Views: 609
Something like this:
Code:
Dim Test As String
Dim Items() As String

Test = File.ReadString(File.DirAssets, "test.txt")

Items = Regex.Split(",", Test)
Msgbox(Items(0).Replace(QUOTE, ""), "")

The contents of "test.txt" is something like
Code:
"AB15", "something", "more", "even more"
 
Upvote 0
i keep getting an error on yours and my try....


Parsing code. Error
Error parsing program.
Error description: Syntax error.
Occurred on line: 35
35 ListView1.AddSingleLine(Items(0).Replace(QUOTE,*""),*"")

Code:
      Do While line <> Null
          Dim Items() As String
         line = Reader.ReadLine
          Items = Regex.Split(",", line)         
          ListView1.AddSingleLine(Items(0).Replace(QUOTE,*""),*"")         
      Loop
 
Upvote 0
Many thanks, the listview populates great but then comes up with an error as follows...

java.lang.NullPointerException

If i press yes to continue it runs fine, how can i stop this error, my code now is...

Code:
   Do While line <> Null
          Dim Items() As String
         line = Reader.ReadLine
          Items = Regex.Split(",", line)   
         Items(0) = Items(0).Replace(QUOTE, "")
         ListView1.AddSingleLine(Items(0))          
      Loop
 
Upvote 0
I assume you must have set line before entering the loop in which case ReadLine is in the wrong place and you are ignoring the first line and processing the null at the end which is giving the exception.

Code:
line = Reader.ReadLine
Do While line <> Null
    Dim Items() As String
    Items = Regex.Split(",", line)    
    Items(0) = Items(0).Replace(QUOTE, "")
    ListView1.AddSingleLine(Items(0))
    line = Reader.ReadLine           
Loop
 
Upvote 0
Back
Top