does anyone have a proper case function?

freak

Member
Does anyone have a "proper" case function that they would like to share? I would like to take a variable such as "SOME STRING WITH WORDS" and change it to "Some String With Words". I'm using ancient, obsolete, unsupported Progress 9.1d and I should upgrade.;)
 

TomBascom

Curmudgeon
Code:
Yes, you should upgrade. What's the hold-up?

Code:
function properCase returns character ( s as character ):
  define variable i as integer no-undo.
  define variable c0 as character no-undo.
  define variable c1 as character no-undo.

  c0 = " ".
  do i = 1 to length( s ):
    c1 = substring( s, i, 1 ).
    if c0 = " " then substr( s, i, 1 ) = upper( c1 ).
    c0 = c1.
  end.
  return s.
end.

display properCase( "some string of stuff" ) format "x(30)".
 

freak

Member
I wrote this after I posted... Yours doesn't handle upper/mixed case input strings.


Code:
FUNCTION proper RETURNS CHAR (INPUT instring AS CHAR).
  DEF VAR X AS INTEGER NO-UNDO.
  DEF VAR newstring AS CHAR NO-UNDO.


  DO X=1 TO LENGTH(instring):
     IF X=1 THEN
        newstring=CAPS(substring(instring,X,1)).

     IF X<>1 AND substring(instring,X - 1,1)<>" " THEN
        newstring=newstring + LC(substring(instring,X,1)).

     IF X<>1 AND substring(instring,X - 1,1)=" " THEN
        newstring=newstring + CAPS(substring(instring,X,1)).
  END.

  RETURN newstring.
END FUNCTION.
 

freak

Member
Almost forgot... We've been doing more and more with php/mysql, everything web. Not sure what the future holds for Progress and us.
 
Top