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