[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

a simple command that splits up a string into numbers and letters

shawn bright

2/5/2009 5:39:00 AM

[Note: parts of this message were removed to make it a legal post.]

Hey all,

i am looking for an easy way to split a string into letters and numbers.
so if i had a string '34JKBY103' i could get ['34', 'JKBY', '103']

I could write up something, but thought that if there was already something
out there that i hav'nt found, it would probably be cleaner.
thanks

sk

6 Answers

Evolution

1/27/2009 6:46:00 PM

0

Zeke wrote:
> "Burton Busk" <burtonlmb@comcast.net> wrote:
>> Since Zeke isn't around, I'll say it for him: Have you bought Darkness
>> yet?
>
> LOL!
>
> Touch?! And thank you, Mr. Burt!
>
> Laurie, you have WIESS. Pretty sure I've given you PdR. Go out and get
> BTR, Darkness & Nebraska. Add PdR, Roxy '78 & Summertime Bruce to these and
> you're all set.
>
> ===================================
> Better bring your own redemption when you come
> To the barricades of heaven, where I'm from.
> Jackson Browne
>
>
>
>

Thanks to all of you for responding... Darkness seems to be the
consensus... so that is what I ordered.

--
Laurie

http://lauriehester.blo...

Rob Biedenharn

2/5/2009 6:03:00 AM

0


On Feb 5, 2009, at 12:39 AM, shawn bright wrote:

> Hey all,
>
> i am looking for an easy way to split a string into letters and
> numbers.
> so if i had a string '34JKBY103' i could get ['34', 'JKBY', '103']
>
> I could write up something, but thought that if there was already
> something
> out there that i hav'nt found, it would probably be cleaner.
> thanks
>
> sk



irb> '34JKBY103'.scan(/\d+|\D+/)
=> ["34", "JKBY", "103"]

that looks like an easy way ;-)

-Rob

Rob Biedenharn http://agileconsult...
Rob@AgileConsultingLLC.com



Tim Greer

2/5/2009 6:11:00 AM

0

shawn bright wrote:

> [Note: parts of this message were removed to make it a legal post.]
>
> Hey all,
>
> i am looking for an easy way to split a string into letters and
> numbers. so if i had a string '34JKBY103' i could get ['34', 'JKBY',
> '103']
>
> I could write up something, but thought that if there was already
> something out there that i hav'nt found, it would probably be cleaner.
> thanks
>
> sk

I don't know if there's anything out there now (there might be), but it
seems pretty simple. Just split on either \d+ or \D+, depending
(unless I'm missing something in your requirement)?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!

shawn bright

2/5/2009 6:33:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

sorry, how do i split on a \d+ ?
sk

On Thu, Feb 5, 2009 at 12:14 AM, Tim Greer <tim@burlyhost.com> wrote:

> shawn bright wrote:
>
> > [Note: parts of this message were removed to make it a legal post.]
> >
> > Hey all,
> >
> > i am looking for an easy way to split a string into letters and
> > numbers. so if i had a string '34JKBY103' i could get ['34', 'JKBY',
> > '103']
> >
> > I could write up something, but thought that if there was already
> > something out there that i hav'nt found, it would probably be cleaner.
> > thanks
> >
> > sk
>
> I don't know if there's anything out there now (there might be), but it
> seems pretty simple. Just split on either \d+ or \D+, depending
> (unless I'm missing something in your requirement)?
> --
> Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
> Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
> and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
> Industry's most experienced staff! -- Web Hosting With Muscle!
>
>

Tim Greer

2/5/2009 6:52:00 AM

0

shawn bright wrote:

> [Note: parts of this message were removed to make it a legal post.]
>
> sorry, how do i split on a \d+ ?
> sk
>
> On Thu, Feb 5, 2009 at 12:14 AM, Tim Greer <tim@burlyhost.com> wrote:
>
>> shawn bright wrote:
>>
>> > [Note: parts of this message were removed to make it a legal
>> > [post.]
>> >
>> > Hey all,
>> >
>> > i am looking for an easy way to split a string into letters and
>> > numbers. so if i had a string '34JKBY103' i could get ['34',
>> > 'JKBY', '103']
>> >
>> > I could write up something, but thought that if there was already
>> > something out there that i hav'nt found, it would probably be
>> > cleaner. thanks
>> >
>> > sk
>>
>> I don't know if there's anything out there now (there might be), but
>> it
>> seems pretty simple. Just split on either \d+ or \D+, depending
>> (unless I'm missing something in your requirement)?
<please don't quote signatures>

Someone posted this already, but:

irb(main):010:0> s = "34JKBY103"
=> "34JKBY103"
irb(main):011:0> s.scan(/\d+|\D+/)
=> ["34", "JKBY", "103"]
irb(main):012:0>



--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!

Tim Greer

2/5/2009 6:53:00 AM

0

Tim Greer wrote:

> shawn bright wrote:
>
>> [Note: parts of this message were removed to make it a legal post.]
>>
>> sorry, how do i split on a \d+ ?
>> sk
>>
>> On Thu, Feb 5, 2009 at 12:14 AM, Tim Greer <tim@burlyhost.com> wrote:
>>
>>> shawn bright wrote:
>>>
>>> > [Note: parts of this message were removed to make it a legal
>>> > [post.]
>>> >
>>> > Hey all,
>>> >
>>> > i am looking for an easy way to split a string into letters and
>>> > numbers. so if i had a string '34JKBY103' i could get ['34',
>>> > 'JKBY', '103']
>>> >
>>> > I could write up something, but thought that if there was already
>>> > something out there that i hav'nt found, it would probably be
>>> > cleaner. thanks
>>> >
>>> > sk
>>>
>>> I don't know if there's anything out there now (there might be), but
>>> it
>>> seems pretty simple. Just split on either \d+ or \D+, depending
>>> (unless I'm missing something in your requirement)?
> <please don't quote signatures>
>
> Someone posted this already, but:
>
> irb(main):010:0> s = "34JKBY103"
> => "34JKBY103"
> irb(main):011:0> s.scan(/\d+|\D+/)
> => ["34", "JKBY", "103"]
> irb(main):012:0>
>


Also, remember, there are several ways to do this. You can use an
actual split() function with a regular expression.

See: http://www.ruby-doc.org/core/classes/S...
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!