I’m trying to split on spaces but one of the data columns has spaces in it and no quotes around it It’s sms exported from my phone I wanna save them to a table Each line looks like the line below The first is the phone number then the date and time, then the body of the sms message and then a single digit 1 or 2 to indicate if the message was sent or received Looks like between time and message body there’s a tab delimeter but the other delimeters are single spaces but then the message body contains single spaces and so does the date and time column How can I split this?
+2124914028 06/09/2017 12:21:56 Are we meeting up for breakfast today? 1
I’m trying to split on spaces but one of the data columns has spaces in it and no quotes around it It’s sms exported from my phone I wanna save them to a table Each line looks like the line below The first is the phone number then the date and time, then the body of the sms message and then a single digit 1 or 2 to indicate if the message was sent or received Looks like between time and message body there’s a tab delimeter but the other delimeters are single spaces but then the message body contains single spaces and so does the date and time column How can I split this?
+2124914028 06/09/2017 12:21:56 Are we meeting up for breakfast today? 1
just split it by parts (simpler for me).
eg,
s=“+2124914028 06/09/2017 12:21:56 Are we meeting up for breakfast today? 1”
=> “+2124914028 06/09/2017 12:21:56 Are we meeting up for breakfast today? 1”
phone,date,time,remaining=s.split(/\s/,4)
=> [“+2124914028”, “06/09/2017”, “12:21:56”, “Are we meeting up for breakfast today? 1”]
The file was all one line with the data delimited by tabs so i wrote a counter routine to treat every multiple of 5 as 1 Worked but now I have a lot of phone numbers formatted differently +19173320500 (808) 741-1112 7184414411 see what I mean How can I uniform all these phone numbers so they’ll list ordered by phone num
Colin
>
> I'm trying to split on spaces but one of the data columns has spaces in it and no quotes around it It's sms exported from my phone I wanna save them to a table Each line looks like the line below The first is the phone number then the date and time, then the body of the sms message and then a single digit 1 or 2 to indicate if the message was sent or received Looks like between time and message body there's a tab delimeter but the other delimeters are single spaces but then the message body contains single spaces and so does the date and time column How can I split this?
>
> +2124914028 06/09/2017 12:21:56 Are we meeting up for breakfast today? 1
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f201139b-f56b-4909-af53-5144e79dbef3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
The file was all one line with the data delimited by tabs so i wrote a counter routine to treat every multiple of 5 as 1 Worked but now I have a lot of phone numbers formatted differently +19173320500 (808) 741-1112 7184414411 see what I mean How can I uniform all these phone numbers so they'll list ordered by phone num
Are the numbers all in the US, or all in another country format? There's an ActiveSupport helper in Rails that can format phone numbers, but it requires that you pass it the country as a parameter (or it defaults to US, I think).