` Printed Icetips Article

Icetips Article



Par2: Function to proper case a name
2000-08-05 -- Bob Campbell
 
I get Name data from an Oracle database, in the same mess as yours. Here's a 
function I wrote to Capitalize the names. It's actually pretty simple.
 
In the data section embed I put:
 
B       BYTE     ! Beginning of word, i.e. the first letter
Ii      BYTE     ! The name has II suffix, e.g. James Madison II
Mc      BYTE     ! The name has Mc, e.g. McEnroe
Idx     SHORT    ! Index or position
 
In the Process Code embed, I put:
 
  B = TRUE
  IF UPPER(SUB(Nam,1,2)) = 'MC'
    Mc = TRUE
    !MESSAGE('Mc = ' & Mc & '|Nam = ' & Nam,'Proper Case',ICON:Asterisk)
  ELSE
    Mc = FALSE
  END
 
  LOOP Idx = 1 TO LEN(CLIP(Nam))
    IF Ii AND Nam[Idx] = 'I'
      B = TRUE
    END
    IF Idx > 1 AND NOT B
      Nam[Idx] = LOWER(Nam[Idx])
    END
    IF Nam[Idx] = '' OR Nam[Idx] = ',' OR Nam[Idx] = '.' OR Nam[Idx] = '-' OR Nam[Idx] =
'(' OR Nam[Idx] = '/'
      B = TRUE
      !MESSAGE('Idx = ' & Idx,'Proper Case',ICON:Asterisk)
    ELSE
      B = FALSE
    END
    IF Mc AND Idx = 2
      B = TRUE
    END
    IF Nam[Idx] = 'I'
      Ii = TRUE
    ELSE
      Ii = FALSE
    END
  END
  !MESSAGE('Nam = ' & Nam,'Proper Case',ICON:Asterisk)
  RETURN(Nam)

 
The prototype is (),STRING
The parameters are (Nam)
 
Here is an example of calling it:
 
    Wor:Employer  = Capitalize(Per:Company)

Hope this helps.



Printed November 21, 2024, 6:26 am
This article has been viewed/printed 35202 times.