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!

Problem with Initial Caps Formula

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
I DLd a function called Initial Caps which capitalized the first letter of every word. My problem is that I am using this formula on a name field which may contain suffixes such as "IV" or "III". What inevitably comes out is:

Mr. & Mrs. John Hopkins, Iii

Can anyone recommend a way to fix this? Thank you in advance for any help!
 
Wrap the function in a big ole ugly replace statement, such as:

replace(replace(replace(initialcaps({table.field}+" ")," Ii "," II")," Iii "," III ")," Iv"," IV ")...etc...

You get the idea.

-k
 
You could try this:



local stringvar array arrval:= split({@data}); //Turns the string to a string array based on spaces
local numbervar lastentry:= UBound(arrval); //Finds the last group in the array
local stringvar array arrshortval := arrval[1 to lastentry-1]; //Makes a new array without the last entry.
local stringvar lastval:= uppercase(arrval[lastentry]); //Gets the last string value from the orignal array.

if lastval in ["I","II","III","IV","V","VI","VII","VIII","IX"] //compares the last array val based on known likely roman numerals
then Propercase(join((arrshortval))) + " " + lastval //if it truly did have a space before it and was a known Romand Numeral, concatenate pieces.

else

Propercase({@data}); //Otherwise just pass the orignal string back, adjusted for propercase.
[/blue]

The Propercase function is in Crystal 10 but I'm not sure what previous versions have it or how well this would work on previous versions. But it works okay in 10.

Good Luck.

Scott.
 
Sorry about that, I was having problems getting "preview post" to work and just had to submit.

The formula should look like this.


local stringvar array arrval:= split({@data}); //Turns the string to a string array based on spaces
local numbervar lastentry:= UBound(arrval); //Finds the last group in the array
local stringvar array arrshortval := arrval[1 to lastentry-1]; //Makes a new array without the last entry.
local stringvar lastval:= uppercase(arrval[lastentry]); //Gets the last string value from the orignal array.

if lastval in ["I","II","III","IV","V","VI","VII","VIII","IX"] //compares the last array val based on known likely roman numerals
then Propercase(join((arrshortval))) + " " + lastval //if it truly did have a space before it and was a known Romand Numeral, concatenate pieces.

else

Propercase({@data}); //Otherwise just pass the orignal string back, adjusted for propercase.
 
Another interesting idea, Scott, I assumed that they were in CR 8.5 or below since they went after the dll.

I had typos in mine anyway:
replace(replace(replace(initialcaps({table.field}+" ")," Ii "," II ")," Iii "," III ")," Iv "," IV ")...etc...

Note that the additional spaces are to prevent altering non roman numerals from being converted.

-k
 
Thanks, synapse. Yeah it would be an unhappy moment if Ivan became IVan. Or Kevin became KeVIn. Customers don't like that kind of thing.

The extra blank you add to the end of your field does pretty much guarantee that the right parts get hit.

I think there's probably a way to solve this with Midstring and a similar treatment looking for the last space (or even the comma if there was a guarantee that it would be present and only appear under these circumstances), although I wouldn't swear to it.

Nice puzzle, byrne1. Hope at least one of these gets you there. Roman suffixes are such a pain to software.

Scott.
 
I'm running an ancient version of CR: 7.0.1.

The REPLACE function is not a valid function in this version and there are several version issues with the other formula provided by SMC.

To add further complications, the suffix is not always at the end of the field:

Mr & Mrs John Smith, IV & Mr & Mrs Richard Jones, III

Creative users!

Anyway, I will continue to look down the roads you have lead me to (ie, a replace function or something similar).

Thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top