Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capitalizing string with multiple spaces 1

Status
Not open for further replies.

awowen

Technical User
Dec 27, 2004
8
Our database stores city names as all caps. I am attempting to output the name as initial caps only. Problem is some city names are three or more words. I kluged up the code below to handle two-word strings but haven't been able to handle three or more. Need to change 'XXX XXX XXX' to 'Xxx Xxx Xxx'.

Version 8.5 against a btrieve database.

if instr({Case_1.CasRelName2}," ") > 0 then
UpperCase (Left ({Case_1.CasRelName2},1))&LowerCase (Mid ({Case_1.CasRelName2},2 ,(tonumber((instr({Case_1.CasRelName2}," "))-1))))&Uppercase(Mid ({Case_1.CasRelName2},(InStr ({Case_1.CasRelName2}," " )+1) , 1)) & LowerCase (Mid ({Case_1.CasRelName2},(InStr ({Case_1.CasRelName2}," " )+2) ,Length ({Case_1.CasRelName2})))
else UpperCase (Left ({Case_1.CasRelName2},1))&LowerCase (Mid ({Case_1.CasRelName2},2 ,Length ({Case_1.CasRelName2})))

Thanks,
 
Download the ProperCase UFL from Business Objects.

Or use something like this:
Code:
local stringvar array la_name:='';
local numbervar l_i;
local stringvar l_result:='';
la_name:=split(lcase({Your.Field}));
for l_i:=1 to ubound(la_name) do
(
  l_result:=l_result & ucase(left(la_name[l_i],1)) & right(la_name[l_i],length(la_name[l_i])-1) & 
  if l_i<ubound(la_name) then " ";  
  
);
l_result;
Naith
 
Thanks Naith!
The code worked like a charm. I wasn't able to use the UFL because our users are running the reports from an app and this caused the report to fail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top