scripting@wanadoo.nl




TitleCase()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
18 March 2002 TitleCase()
AuthorHumberto Roche-García (Puerto Rico)
Action Places correct case on first position of character string and to the rest of characters in string.
SyntaxTitleCase ($ExpC, $ExpN) 
Parameters
  • $ExpC (Required / String) Character string to convert accordingly
  • $ExpN (Optional / Numeric) Negative parameter to revert case on string 
  • RemarksSkips Special Characters or numbers
    Skips Empty strings
    Always after a space or a period or punctuation marks such as (?), (.), (!) puts the correct case, not after any other special character 
    ReturnsCorrect case on first position of character string in Uppercase and rest of string in Lowercase. If parameter passed as -1 then first position of character string in Lowercase and rest of string in Uppercase. 
    DependenciesNone. 
    Examples
    $THIS = TITLECASE("hola")
    ? "THIS=Hola compare to $THIS"
    ? "-----1"
    $THIS = TITLECASE("hOLA")
    ? "THIS=Hola compare to $THIS"
    ? "-----2"
    $THIS = TITLECASE("hOla? hola HOLA! hOLA. hola")
    ? "THIS=Hola? Hola Hola! Hola. Hola compare to $THIS"
    ? "-----3"
    $THIS = TITLECASE("Hola")
    ? "THIS=Hola compare to $THIS"
    ? "-----4"
    $THIS = TITLECASE("Hola", -1)
    ? "THIS=hOLA compare to $THIS"
    ? "-----5"
    $THIS = TITLECASE("hola", -1)
    ? "THIS=hOLA compare to $THIS"
    ? "-----6"
    $THIS = TITLECASE("HOLA", -1)
    ? "THIS=hOLA compare to $THIS"
    ? "-----7"
    $THIS = TITLECASE("hOla", -1)
    ? "THIS=hOLA compare to $THIS"
    ? "-----8"
    $THIS = TITLECASE("hola Hola? hOLA! hOLa hOLa. HOLA? HOLA", -1)
    ? "THIS=hOLA hOLA? hOLA! hOLA hOLA. hOLA? hOLA compare to $THIS"
    ? "-----9"
    $THIS = TITLECASE("hola Hola?hOLA!hOLahOLa.HOLA?HOLA")
    ? "THIS=Hola Hola?Hola!Holahola.Hola?Hola compare to $THIS"
    ? "-----10"
    $THIS = TITLECASE("hola Hola?hOLA!hOLahOLa.HOLA?HOLA", -1)
    ? "THIS=hOLA hOLA?hOLA!hOLAHOLA.hOLA?hOLA compare to $THIS"
    ? "-----11"
    
     
    Source
    FUNCTION TitleCase ($expc, OPTIONAL $expn)
      ; Places correct case on first position of character string
      ; Skips Special Characters or numbers
      ; Skips Empty strings
      ; Always after a space or a period or punctuation marks such as (?), (.), (!) puts the correct case, not after any other special character
    
      $localstart = 1
      $locallen = Len($expc)
      $localprevchar = ""
      $titlecase = ""
      WHILE ($localstart <= $locallen)
        $localstring = Substr($expc, $localstart, 1)
        IF ($expn = -1)
          IF ($localprevchar = "") OR (Asc($localprevchar) = 46) OR (Asc($localprevchar) = 32) OR (Asc($localprevchar) = 63) OR (Asc($localprevchar) = 33) ; Check for nothing, period, space, question mark or exclamation mark
            IF (Asc($localstring) >= 65) AND (Asc($localstring) <= 90)    ; In Uppercase
              $localstring = Chr(Asc($localstring) + 32)                  ; Convert to Lowercase
            ENDIF
          ELSE
            IF (Asc($localstring) >= 97) AND (Asc($localstring) <= 122)   ; In Lowercase
              $localstring = Chr(Asc($localstring) - 32)                  ; Convert to Uppercase
            ENDIF
          ENDIF
        ELSE
          IF ($localprevchar = "") OR (Asc($localprevchar) = 46) OR (Asc($localprevchar) = 32) OR (Asc($localprevchar) = 63) OR (Asc($localprevchar) = 33) ; Check for nothing, period, space, question mark or exclamation mark
            IF (Asc($localstring) >= 97) AND (Asc($localstring) <= 122)   ; In Lowercase
              $localstring = Chr(Asc($localstring) - 32)                  ; Convert to Uppercase
            ENDIF
          ELSE
            IF (Asc($localstring) >= 65) AND (Asc($localstring) <= 90)    ; In Uppercase
              $localstring = Chr(Asc($localstring) + 32)                  ; Convert to Lowercase
            ENDIF
          ENDIF
        ENDIF
        $titlecase = $titlecase + $localstring
        $localprevchar = $localstring
        $localstart = $localstart + 1
      LOOP
    ENDFUNCTION ; - TitleCase -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter