Paul, Thanks for this. I see that you have gone about things a different way and I will give this a try, thanks. -------------------------------------------------- From: "Paul Magill" <magills@xxxxxxxxxxx> Sent: Wednesday, July 07, 2010 1:39 PM To: <jawsscripts@xxxxxxxxxxxxx> Subject: [jawsscripts] Re: String Segment Count > Hi Mike, > > I've joined this a bit late, and have taken a different approach... > > see below: > > The function StringProperNames, I have ?used for some years now for its > stated purpose, and I've just tested the proposed FormatNamePrefix > function, > & I think it may suit your needs. > > > > It requires that the first letter of all the names be already upper case, > and all the rest be lower case, which is what StringProperNames does. > > > > It can handle other prefixes other than"Mc", such as "Mac". > > Prefixes such as O'Brien are already handled by StringProperNames. > > > > It does not use stringSegment, but proceeds along the string from left to > right. > > see the test script at the bottom for sample use. > > > > Regards, > > Paul from Aust > > > > code begins: > > > > String Function StringProperNames (string InString) > > ; to convert a string containing names so that the first letter of each > name > is upper case, & the remainder is lower case > > VAR > > INT Position, INT EndPosition, INT PreviousCharWasLetter, > > STRING TempString, STRING CurrentChar > > LET InString = StringLower (InString) > > LET Position = 1 > > LET EndPosition = StringLength (Instring) > > LET PreviousCharWasLetter = False > > LET TempString = " " ;Space ; to prevent numbers being added. is removed > before return > > While (Position <= EndPosition) > > LET CurrentChar = SubString (InString, Position, 1) > > If (CurrentChar >= "a") && (CurrentChar <= "z") THEN ; current char is a > letter > > IF PreviousCharWasLetter THEN ; this letter is not the first letter of the > word > > LET TempString = TempString + CurrentChar ; remains lower case > > ELSE ; this letter is the first letter of the word as the previous char > was > not a letter > > LET TempString = TempString + StringUpper (CurrentChar) > > ENDIF ; PreviousCharWasLetter > > LET PreviousCharWasLetter = True ; set true so next cycle knows this > > ELSE ; current character is not a letter > > LET TempString = TempString + CurrentChar > > LET PreviousCharWasLetter = False > > ENDIF; current character is a letter > > LET Position = Position + 1 > > EndWhile ; not at end of string > > RETURN (stringChopLeft (TempString, 1)) > > EndFunction > > ? > > String Function FormatNamePrefix (string InString, string Prefix) > > ; it is essential that the prefix is in the correct case. example. "Mc" > > VAR > > INT PrefixLength, > > INT CutPoint, > > STRING ReturnString > > LET PreFixLength = StringLength (Prefix) - 1 > > ; minus 1 is required, so that StringLeft gets no more than up to the end > of > the prefix. see below & in the while loop > > LET CutPoint = StringContains (InString, Prefix) + PrefixLength > > While (CutPoint > PrefixLength) > > ; when no more instances of the prefix are found, CutPoint will be the > length of the prefix > > LET ReturnString = ReturnString + StringLeft (InString, CutPoint) + > StringUpper (SubString (InString, CutPoint + 1, 1)) > > ; copy to ReturnString, the portion of InString up to the end of the first > found prefix + the uppercase version of the next character > > LET InString = stringChopLeft (InString, CutPoint + 1) > > ; chop from the left of InString, up to and including the character > following the prefix > > LET CutPoint = StringContains (InString, Prefix) + PrefixLength > > EndWhile; still finding the prefix > > Return (ReturnString + InString) ; InString is remainder of unprocessed > source string > > EndFunction > > ? > > Script TestOnF6 () > > var > > string TestString > > Let TestString = "MCTAVISH MCBETH MCTOBY-MCINTOCH MCMYER " > > let TestString = StringProperNames (TestString) > > let TestString = FormatNamePrefix (TestString, "Mc") > > CopyToClipboard (TestString) > > ; McTavish McBeth McToby-McIntoch McMyer > SayString ("done ") > > EndScript > > ? > > > ----- Original Message ----- > From: "Mike" <mike_sharp@xxxxxxxxxxxxx> > To: <jawsscripts@xxxxxxxxxxxxx> > Sent: Tuesday, July 06, 2010 5:39 PM > Subject: [jawsscripts] Re: String Segment Count > > > Geoff and all. > > I tried as suggested and it did not work. Let me explain what I am trying > to > achieve and paste the code thus far. > I am capturing names from a screen which need to be formatted in the > correct > way. This particular function has to check for names beginning with Mc and > format it in such a way that the name appears like McTavish. My script > works > where the string has a blank space between each forename or surname but in > some cases the name may be hyphenated. I need the string segment count to > look for a blank space and a hyphen. Here is my working code so far, maybe > someone can critique what I have done and suggest a way forward. > As always..thanks in advance for the help. > > __________� > > View the list's information and change your settings at > http://www.freelists.org/list/jawsscripts > > __________� View the list's information and change your settings at http://www.freelists.org/list/jawsscripts