Run this:
sNum = "8005551212"
re = /(\d\d\d)(\d\d\d)(\d\d\d\d)/
md = re.match(sNum)
print sNum + " => "
puts "(#{md[1]}] #{md[2]}-#{md[3]}"
__END__
Output:
8005551212 => (800] 555-1212
HTH,
Richard
Guest wrote:> Hello,
>
> I need to split the phone number into three fields (000) 000 0000.
>
> --
> Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---