-1

I have to find some values in a CSV. Therefore I read the value of the column I need in a string. The strings I obtain can be like this:

String1 : "0;0;0;36480;0;0;0"


String2: "809;623;215;36188;420;418;65"

I just need the 4th value of each string (36480 , 36188)

I there a way to count the ";" in a string and save the values between the 3 and 4 ";"

I tried with string.find but I am not able to get the values I need...

Thanks

Sam
  • 2,935
  • 1
  • 19
  • 26
relash
  • 199
  • 1
  • 1
  • 4

1 Answers1

1

You can use the str.split method to split the string to a list. And then use the index to get the required element.

Ex:

String1 = "0;0;0;36480;0;0;0"
print(String1.split(";")[3])
String2 = "809;623;215;36188;420;418;65"
print(String2.split(";")[3])

Output:

36480
36188
Rakesh
  • 81,458
  • 17
  • 76
  • 113