Posts Tagged capitalize

String case handler :: reg-exp to check whether the string is upcase or not

# #This function basically checks with a regular expression whether the passed value matches with the regular expression or not ,
# #if it does then in that case it will return match data and we wont do a titleize else we will go for titleizing the data , as i am,
# #considering that the data which is a string can be of 3 formats (1/ all upcase 2/ all lowercase 3/ mixed-case), probably this wil handle all
# # the three cases .

def string_case_handler(str_value)
if (/^[A-Z]*$/.match(str_value) == nil)
#if the string doesnt matches then we will titleize it
return str_value.capitalize
else
#if we get matchdata object ,ie it gets matches , no need to do anything just print it
return str_value
end
end

Also if we want to capitalize only the first letter then replace this

str_concat = str_value.first.capitalize + str_value.slice(str_value.first.capitalize.length ,str_value.length)
return str_concat

Add comment February 14, 2008


Recent Posts

Tags

Active Record australian gp calendar date select capistrano capitalize debugging Debugging in rails edge rails formula 1 For those who dont want to update the prototype.js fun Fun baby fun google html in join javascript linus vs windows compatibility linux logging love song malaysian gp 2008 results melbourne migrations music mysql plugin poetry rails regexp regular expression results formula 1 opening race romantic poetry ror Ruby ruby on rails safe html sms song SQL string case handler for strings syantax syntax error for migrations on linux Text Area they can checkout 1.8.3 of the calender date select

Blogroll

Pages