Subject Re: proper()
From Charlie <tm@tc.com>
Date Mon, 14 Apr 2025 14:58:16 -0400
Newsgroups dbase.getting-started

Thanks Mervyn, that works great!!

Mervyn Bick Wrote:

> On 2025/04/13 14:50, Charlie wrote:
> > Thanks Mervyn!!  I can put this in with my functions.
> >
> > Let me ask you this.  At the end of each sentence I use a period, question mark or explanation marl.  Then one or two spaces.  How would I code this function so it would recognize the end of the sentence and if there is more text to start the next sentence with a capital letter?
> >
> > I could possibly figure this out but know it would probably be easier for you.
>
> Although to do this only with dBASE commands would be possible, the
> coding to step through the string to find the start of each sentence
> would be a nightmare.
>
> Using a Regular Expression makes it a piece of cake. :-)
>
>    function first_upper(cStrx)
>        oRegExp = new OleAutoClient("VBScript.RegExp")
>        oRegExp.global := true
>        oRegExp.ignoreCase := true
>        oRegExp.multiline := true
>        oRegExp.pattern :=  "(^\s*\S)|(\.|\?|\!)\s*\S"
>
>        aMatch = oRegExp.execute(cstrx)
>        for n = 0 to aMatch.count-1
>              cMatch = aMatch.item(n).value
>              nLen = aMatch.item(n).length
>              nPos = aMatch.item(n).firstIndex
>              cStrx = stuff(cStrx,nPos+nLen,1,upper(right(cMatch,1)))
>        next
>        return cStrx
>
> First_upper.prg, test_first_upper.prg and first_upper_test.txt are attached.
>
> Mervyn.
>
>
> i live in a condo!   test CRLF.
> is the condo life for me?  The condo life.  the end.  function first_upper(cStrx)
>       oRegExp = new OleAutoClient("VBScript.RegExp")
>       oRegExp.global := true
>       oRegExp.ignoreCase := true
>       oRegExp.multiline := true
>       oRegExp.pattern :=  "(^\s*\S)|(\.|\?|\!)\s*\S"
>
>       aMatch = oRegExp.execute(cstrx)
>       for n = 0 to aMatch.count-1
>             cMatch = aMatch.item(n).value
>             nLen = aMatch.item(n).length
>             nPos = aMatch.item(n).firstIndex
>             cStrx = stuff(cStrx,nPos+nLen,1,upper(right(cMatch,1)))
>       next  
>       return cStrx
> clear
> cStr1 = 'i live in a condo.'
> cStr2 = 'the condo life for me.'
> cStr3 = 'The first character was upper case to start with'
>
> ?first_upper(cStr1)
> ?first_upper(cStr2)
> ?first_upper(cStr3)
> ?
> cStr = 'i live in a condo!   test CRLF.'+chr(13)+chr(10)+'is the condo life for me?  The condo life.  the end.'
> ?cStr
> ?
> f = new file()
> f.create('first_upper_test.txt')
> f.write(cStr,len(cStr))
> f.close()
> ? first_upper(cStr)
> ?
> f = new file()
> f.open('first_upper_test.txt')
> nSize = f.size('first_upper_test.txt')
> cRead = first_upper(f.read(nsize))
> f.create('first_upper_test_output.txt')
> f.write(cRead,len(cRead))
> f.close()
> ?cRead



Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0