I have an address field that pulls the street address in all caps. I need to pull and merge the address into a customer letter. I would like to make the address line proper case. For example: 10 NE OAK FIELD RD should be 10 NE Oak Field Rd and PO BOX 245 should be PO Box 245. I’m still pretty new to using strings to convert text. Any help would be appreciated. Thank you.
Terry is quite right that using INITCAPS() can lead to some ugly anomalies. I hate all-caps in my reports, though, so where I can predict problems, I will often handle them with a case statement, and let the rest of the chips fall where they may.
(The following code works fine against an Oracle back-end):
#/Proper case Service Group Descriptions via INITCAP and brute force/#
CASE [Presentation Layer].[REFCDS].[MEANING]
WHEN ‘CBA’ THEN ‘CBA’
WHEN ‘CLASS’ THEN ‘CLASS’
WHEN ‘HCS’ THEN ‘HCS’
WHEN ‘HCS-O’ THEN ‘HCS-O’
WHEN ‘ICF/IID NON-STATE’ THEN ‘ICF/IID Non-State’
WHEN ‘ICF/IID CAMPUS/STATE’ THEN ‘ICF/IID Campus-State’
WHEN ‘ICF/IID COMM/STATE’ THEN ‘ICF/IID Comm/State’
WHEN ‘LTC SUPPORT SERVICES (FOR PROVIDER ENROLLMENT)’ THEN ‘LTC Support Services (for Provider Enrollment)’
WHEN ‘MEDICALLY DEPENDENT CHILDREN PROGRAM (MDCP)’ THEN ‘Medically Dependent Children Program (MDCP)’
WHEN ‘MRA’ THEN ‘MRA’
WHEN ‘PACE’ THEN ‘PACE’
WHEN ‘STAR+PLUS’ THEN ‘Star+Plus’
ELSE
INITCAP([Presentation Layer].[REFCDS].[MEANING]) || ’ ’
END
I often use INITCAPS() for name fields, and just accept output like:
Mcdonald instead of McDonald
Macpherson instead of MacPherson
Von Beethoven instead of von Beethoven
etc.
All caps avoids the anomalies, but at the expense of overall legibility. I just haven’t found it worthwhile to take the time to deconstruct strings and handle the known problems like Mc, Mac and von/van etc.
You pays your money and you takes your choice.
Thanks again - sorry I’m so thick - I’m still pretty new at all this. I will find the underlying database, hope that it it Oracle, and hope I can use INTICAPS()!
You have an underlying database! If it Oracle then you can use INITCAPS() function
Thanks Terry - it is just cognos, not Oracle. I think it is going to be complex - I appreciate your help. I will probably end up fixing the initials in excel after I output the data. I didn’t think there would be an easy fix for this. Cheers!
Thanks! I will give this a try
public string ToProperCase(string str)
{
if (string.IsNullOrEmpty(str))
return str;
return char.ToUpper(str[0]) + str.Substring(1).ToLower();
}
=========how to call==========
Label1.Text = ToProperCase(“Pass your string here excluding quote marks”);
What is your database/ If its Oracle then use INITCAPS() function - even with this function you will probably encounter the problems outlined below!
If its anything else then It can be quite complex to convert to lower case and leave initial capitals.
In Your example 10 NE Oak Field Road would probably become 10 Ne Oak Field Road
And PO Box 245 would probably become Po Box 245
Quite often the safest option is to leave addresses in the case they are in (convert them to upper case if all in lower case)