B4J Question Import CSV File

lucdrb

Active Member
Licensed User
Longtime User
Hi

I would like import a csv file wich the each line are like the following:

"dd/MM/yyyy","08:27:36","CEST","xxxx ","xxxxx","Terminé","EUR","40,10","","40,10",

I've try with split(text,",") but the coma from the number is use like a separator and the result keep the " character.

Do you have any idea to get a array or a list with each information without the " and the amounts with the , ?

Thanks in advance
Luc
 

lucdrb

Active Member
Licensed User
Longtime User
The CSV file is build by Paypal (activity history) I can also make a tab separated file, but I don't know how to split a tab separated line.
If you know how, the help will be welcome
 
Upvote 0

lucdrb

Active Member
Licensed User
Longtime User
For keirS:
The stringutils could work but the character set of the file is encoded in WINDOWS-1252 and I get accentued french character that the stringutils import don't have.
When it doesn't want to work it don't work
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Try this:

B4X:
Dim Spllited() As String
    Spllited = Regex.Split($",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"$,$""dd/MM/yyyy","08:27:36","CEST","xxxx ","xxxxx","Terminé","EUR","40,10","","40,10""$)
   
    For i = 0 To Spllited.Length - 1
        Log(Spllited(i))
       
    Next
 
Upvote 0

lucdrb

Active Member
Licensed User
Longtime User
Thanks, It's work.

I see that regex is the solution, I should learn it as fast as possible.

If I may, do you know how to delete the quote?

Luc
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
You don't want to do that in the Split as you would get different lengths of array due to empty values.

B4X:
Spllited = Regex.Split($",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"$,$""dd/MM/yyyy","08:27:36","CEST","xxxx ","xxxxx","Terminé","EUR","40,10","","40,10""$)
  
    For i = 0 To Spllited.Length - 1
        Log(Spllited(i))
    If Spllited(i).IndexOf($"""$) > -1 And Spllited(i).Length > 2 Then
       Log(Spllited(i).SubString2( Spllited(i).IndexOf($"""$)+1,Spllited(i).LastIndexOf($"""$)-1))
    Else
        Log("Empty")
    End If
      
    Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…