Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Proper() function
Message
De
11/07/2003 10:17:07
 
 
À
11/07/2003 08:38:03
Samir Chheda
Remittag Software Pvt. Ltd.
Mumbai, Inde
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00808359
Message ID:
00809195
Vues:
35
Samir, Ok, see if this fits your needs:
LPARAMETERS tcText
LOCAL lnNewText, lcTemp, lcChar, llUpper
lcNewText = ""
tcText = LTRIM(tcText)
lcTemp = tcText	&& set temp string to tcText
llUpper = .F.
* if 1st char not a sentence ender
* set 1st char to upper and set lcTemp and lnStart accordingly
IF !(LEFT(tcText, 1) $ ".?!")
   lcNewText = UPPER(LEFT(tcText, 1))
   lcTemp = LTRIM(SUBSTR(tcText, 2))
ELSE
   llUpper = .T.   && upper case next character
ENDIF
DO WHILE !EMPTY(lcTemp)
   lcChar = LEFT(lcTemp, 1)   && get first char
   IF llUpper AND lcChar<> " "   && is it a space after .?!
      lcChar = " " + UPPER(lcChar)   && no, so add a space
      lcTemp = SUBSTR(lcTemp,2)   && shrink lctemp
   ELSE
      IF llUpper AND lcChar = " "   && space?
         lcChar = lcChar + UPPER(SUBSTR(lcTemp,2,1))   && yes, so get next char too
         lcTemp = SUBSTR(lcTemp, 3)   && shrink lctemp
      ELSE
         lcTemp = SUBSTR(lcTemp,2)    && shrink lctemp
      ENDIF
   ENDIF
   IF LTRIM(lcChar) $ ".?!"    && set llUpper
      llUpper = .T.
   ELSE
      llUpper = .F.
   ENDIF
   lcNewText = lcNewText + lcChar   && add to lcNewText
ENDDO

RETURN lcNewText
Alan

>Yes Alan,
>
>The code did not work on the string sent by you. I have made some modifications in the code. It works fine, but there is one more problem with it. When a string has more than one consecutive dots(.), it fails.
>
>Try, the code using the following string -
>abc.def..ghi...
>
>If you find some solution, please let me know.
>
>Regards,
>Samir
>
>*****Code snippet
>Local lcNewText
>
>lcNewText = ""
>tcText = Ltrim(tcText)
>cTmp = ""
>iCnt = 0
>For iLen = 1 To Getwordcount(tcText,'.')
> lcNewText = LOWER(Substr(tcText,iCnt+1,IIF(Atc('.',Right(tcText,Len(tcText)-iCnt))=0,Len(tcText)-iCnt,Atc('.',Right(tcText,Len(tcText)-iCnt)))))
>
> iCnt = iCnt + LEN(lcNewText)
>
> lcNewText = ALLTRIM(lcNewText)
>
> lcNewText = UPPER(Left(lcNewText,1)) + Substr(lcNewText,2)
>
> cTmp = cTmp + lcNewText + SPACE(1)
>Endfor
>lcNewText = cTmp
>Return Rtrim(lcNewText)
>
>**********
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform