[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

how to capitalize a number of characters in a word

Cheyne Li

7/22/2008 9:11:00 PM

Hi, there

For example, how can i get "HelLoha" from "helloha"

Looking forward to hearing from you. Thanks in advance
--
Posted via http://www.ruby-....

12 Answers

Marc Heiler

7/22/2008 9:51:00 PM

0

> For example, how can i get "HelLoha" from "helloha"

Probably one hundred million ways. One could be this:


x = "helloha" # => "helloha"
x.capitalize! # => "Helloha"
x[2,1] = x[2,1].capitalize # => "L"


x # => "HeLloha"


And yeah instead of 2,1 you would do 3,1.
--
Posted via http://www.ruby-....

Xavier Noria

7/22/2008 9:51:00 PM

0

On Tue, Jul 22, 2008 at 11:10 PM, Cheyne Li
<happy.go.lucky.clr@gmail.com> wrote:

> For example, how can i get "HelLoha" from "helloha"

Can you explain why those are precisely the ones to capitalize?

Todd Benson

7/23/2008 2:32:00 AM

0

On Tue, Jul 22, 2008 at 9:10 PM, Cheyne Li <happy.go.lucky.clr@gmail.com> wrote:
> Hi, there
>
> For example, how can i get "HelLoha" from "helloha"

Here's one for fun...

SEPARATION, s = 32, 'helloha'
(my_letters = [0, 3]).each {|b| s[b] -= SEPARATION}
puts s

...it's goofy, because I'm golfing and also trying to be descriptive
at the same time :-)

Of course, I'm making a large assumption that the letters to be
capitalized are based on position.

Here's a contrived one...

include 'matrix'
(Vector[*'helloha'.unpack('C*')] - Vector[1,0,0,1,0,0,0] * 32).to_a.pack('C*')

...umm, ugly.

Todd

Raveendran Jazzez

7/23/2008 4:18:00 AM

0

Cheyne Li wrote:
> Hi, there
>
> For example, how can i get "HelLoha" from "helloha"
>
> Looking forward to hearing from you. Thanks in advance

Hi Li,

irb(main):016:0> a="HelLoha"
=> "HelLoha"
irb(main):017:0> a.downcase
=> "helloha"
irb(main):018:0>

Regards,
P.Raveendran
http://raveendran.wor...
--
Posted via http://www.ruby-....

Raveendran Jazzez

7/23/2008 4:21:00 AM

0

Raveendran Jazzez wrote:
> Cheyne Li wrote:
>> Hi, there
>>
>> For example, how can i get "HelLoha" from "helloha"
>>
>> Looking forward to hearing from you. Thanks in advance
>
> Hi Li,
>
> irb(main):016:0> a="HelLoha"
> => "HelLoha"
> irb(main):017:0> a.downcase
> => "helloha"
> irb(main):018:0>
>
So simply reversible

irb(main):016:0> a="HelLoha"
=> "HelLoha"
irb(main):017:0> a.downcase
=> "helloha"
irb(main):018:0> a="helloha"
=> "helloha"
irb(main):019:0> a=a.capitalize!
=> "Helloha"
irb(main):020:0> a=a[0,3]+a[3,1].capitalize!+a[4,3]
=> "HelLoha"
irb(main):021:0>


> Regards,
> P.Raveendran
> http://raveendran.wor...

--
Posted via http://www.ruby-....

Todd Benson

7/23/2008 4:42:00 AM

0

On Tue, Jul 22, 2008 at 11:18 PM, Raveendran Jazzez
<jazzezravi@gmail.com> wrote:
> Cheyne Li wrote:
>> Hi, there
>>
>> For example, how can i get "HelLoha" from "helloha"
>>
>> Looking forward to hearing from you. Thanks in advance
>
> Hi Li,
>
> irb(main):016:0> a="HelLoha"
> => "HelLoha"
> irb(main):017:0> a.downcase
> => "helloha"
> irb(main):018:0>
>
> Regards,
> P.Raveendran

There must be a language barrier. I thought the point was to turn
'helloha' _into_ 'HelLoha', and not the reverse.

Todd

Raveendran Jazzez

7/23/2008 4:55:00 AM

0

Todd Benson wrote:
> On Tue, Jul 22, 2008 at 11:18 PM, Raveendran Jazzez
> <jazzezravi@gmail.com> wrote:
>> => "HelLoha"
>> irb(main):017:0> a.downcase
>> => "helloha"
>> irb(main):018:0>
>>
>> Regards,
>> P.Raveendran
>
> There must be a language barrier. I thought the point was to turn
> 'helloha' _into_ 'HelLoha', and not the reverse.
>
> Todd


Hi All(Todd),

Yes. mistake from my side sorry for the inconvenience.

Regards,
P.Raveendran
http://raveendran.wor...
--
Posted via http://www.ruby-....

Todd Benson

7/23/2008 5:03:00 AM

0

On Tue, Jul 22, 2008 at 11:54 PM, Raveendran Jazzez
<jazzezravi@gmail.com> wrote:
> Yes. mistake from my side sorry for the inconvenience.

Well, you might be right with your first post, since you never know
what the original poster meant. Not everyone, after all, has a
command of the english language. And that would include me, lol.

Todd

Cheyne Li

7/23/2008 3:29:00 PM

0

Todd Benson wrote:
> On Tue, Jul 22, 2008 at 11:18 PM, Raveendran Jazzez
> <jazzezravi@gmail.com> wrote:
>> => "HelLoha"
>> irb(main):017:0> a.downcase
>> => "helloha"
>> irb(main):018:0>
>>
>> Regards,
>> P.Raveendran
>
> There must be a language barrier. I thought the point was to turn
> 'helloha' _into_ 'HelLoha', and not the reverse.
>
> Todd

Thank you~
--
Posted via http://www.ruby-....

Cheyne Li

7/23/2008 4:13:00 PM

0

Marc Heiler wrote:
>> For example, how can i get "HelLoha" from "helloha"
>
> Probably one hundred million ways. One could be this:
>
>
> x = "helloha" # => "helloha"
> x.capitalize! # => "Helloha"
> x[2,1] = x[2,1].capitalize # => "L"
>
>
> x # => "HeLloha"
>
>
> And yeah instead of 2,1 you would do 3,1.

Thank you very much. It helps a lot
--
Posted via http://www.ruby-....