Page 1 of 1

PCase() - for proper casing...

Posted: Sat May 31, 2014 7:58 pm
by akee
I notice we don't have a PCase() function so here's my version... 8)

Code: Select all

Procedure$ PCase(arg_String$, arg_All = #True, arg_Punctuations$ = ".?!")
  Protected tmp_String$
  Protected tmp_Around, tmp_Length, tmp_Char$, tmp_NextUp
  tmp_Length = Len(arg_String$)
  tmp_NextUp = #True
  For tmp_Around = 1 To tmp_Length
    tmp_Char$ = Mid(arg_String$, tmp_Around, 1)
    If FindString(arg_Punctuations$, tmp_Char$) > 0
      tmp_String$ = tmp_String$ + tmp_Char$
      tmp_NextUp = #True
    ElseIf tmp_Char$ = " "
      tmp_String$ = tmp_String$ + tmp_Char$
      If arg_All
        tmp_NextUp = #True
      EndIf
    Else
      If tmp_NextUp
        tmp_String$ = tmp_String$ + UCase(tmp_Char$)
        tmp_NextUp = #False
      Else
        tmp_String$ = tmp_String$ + LCase(tmp_Char$)
      EndIf
    EndIf
  Next
  ProcedureReturn tmp_String$
EndProcedure


a$ = "this is a test. this is only a test. to proper case a string and make it look nice. ups words after . dots ? questions marks and ! exclamations."
b$ = "you can add your own. example * proper casing $ proper casing & proper casing."

Debug a$
Debug PCase(a$)
Debug PCase(a$, #False)
Debug b$
Debug PCase(b$)
Debug PCase(b$, #False)
Debug PCase(b$, #False, ".$")