Forum Moderators: coopster & phranque

Message Too Old, No Replies

Convert to uppercase

         

SlowMove

9:41 pm on Feb 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone know how to do a substitution where every letter that follows "$" is capitalized, and then the "$" is removed from the string? So, "$theString" would be converted to "TheString"


$text =~ s///g;

The code above would probably work if I understood regular expressions ¦:@(

PCInk

9:46 pm on Feb 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$text =~ s/\$(.)/uc($1)/eg;

Which swaps $ and the next character (the dot), putting the next char into $1 in the replacement. Then use a function (uc) with $1 (the character) as the parameter. Use e as well as g as the final operator (which means expression - the replacement will be a calculation and not a normal straight swap).

SlowMove

9:56 pm on Feb 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you very much.

Storyteller

1:18 pm on Feb 3, 2004 (gmt 0)

10+ Year Member



A dot can match not only letters. This one is better:

$text =~ s/\$([a-z])/\u$1/ig;

gethan

1:51 pm on Feb 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't forget accented and foriegn but valid characters...

I'd suggest a \w for any word character.

$text =~ s/\$(\w)/\u$1/ig;

Storyteller

7:37 am on Feb 4, 2004 (gmt 0)

10+ Year Member



\w will also match digits and underscores