3
$\begingroup$

I did the following code to get data from a list:

Partition[Flatten[StringCases[Flatten[del2], {__ ~~ ":" ~~ _ ~~ ($1___) ..} -> { $1}, Infinity], 2], 23]

Where del2 is a list of strings data:

{{"report_id: 72431", "city: Duque de Caxias", "state: Rio de Janeiro", "country: BR", "report_date_local: 2015-10-16 02:58:00", "report_date_utc: 2015-10-16 05:58:00", "timezone: BRT", "latitude: -22.754167", "longitude: -43.294351", "altitude: 6.669782", "moving_direction: UpLeftToDownRight", "magnitude: -18.00", "duration: 1.50", "looking_azimuth: 218.67000", "initial_azimuth: 203.16000", "initial_altitude: 30", "final_azimuth: 256.93000", "final_altitude: 24", "rating: 1", "record_date: 2015-10-16 15:29:33", "first_name: MAycon", "last_name: S", "descent_angle: 94.00"}, {"report_id: 72452", "city: Rio de Janeiro", "state: Rio de Janeiro", "country: BR", "report_date_local: 2015-10-16 02:01:00", "report_date_utc: 2015-10-16 05:01:00", "timezone: BRT", "latitude: -22.961191", "longitude: -43.165434", "altitude: 21.876047", "moving_direction: DownLeftToUpRight", "magnitude: -27.00", "duration: 7.50", "looking_azimuth: 349.94000", "initial_azimuth: 253.72000", "initial_altitude: 47", "final_azimuth: 355.90000", "final_altitude: 59", "rating: 1", "record_date: 2015-10-16 20:09:27", "first_name: Petula ", "last_name: P", "descent_angle: 52.00"},....}

And the final result is the parameters of each sublists:

{{"72431", "Duque de Caxias", "Rio de Janeiro", "BR", "0", "0", "BRT", "-22.754167", "-43.294351", "6.669782", "UpLeftToDownRight", "-18.00", "1.50", "218.67000", "203.16000", "30", "256.93000", "24", "1", "3", "MAycon", "S", "94.00"}, {"72452", "Rio de Janeiro", "Rio de Janeiro", "BR", "0", "0", "BRT", "-22.961191", "-43.165434", "21.876047", "DownLeftToUpRight", "-27.00", "7.50", "349.94000", "253.72000", "47", "355.90000", "59", "1", "7", "Petula ", "P", "52.00"},.....}

But my code gets only the final digits of the each substrings date and hours

(..,"_date_local:.....", "date_utc:..........",...,"record_date:...",... )

How can I improve this code to include date and hour correctly in the final list?

$\endgroup$
2
  • 1
    $\begingroup$ list /. s_String :> Last[StringSplit[s, ": "]]? $\endgroup$ Commented Nov 7, 2015 at 5:16
  • $\begingroup$ Perfect. Simple, clean and incredible short. Thank you J.M. $\endgroup$
    – locometro
    Commented Nov 7, 2015 at 11:24

1 Answer 1

2
$\begingroup$

To settle this: one merely needs to use ": " as a unique delimiter for StringSplit[].

list /. s_String :> Last[StringSplit[s, ": "]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.