.cFullName = alltrim(strtran(.cFullName," "," "))>...does not strip out both occurences of " " (two adjacent spaces).
>? strtran("Keith James Payne"," "," ") > >lcTest = "Keith James Payne" >? strtran(lcTest," "," ") >>
>local lcTest, loTest > >lcTest = "Keith James Payne" >? alltrim(strtran(lcTest," "," ")) > >loTest = createobject("test1") > >define class test1 as Custom > cTest = "Keith James Payne" > > > procedure init > > ? strtran(this.cTest," "," ") > with this > ? strtran(.cTest," "," ") > ? alltrim(strtran(.cTest," "," ")) > endwith > endproc >enddefine >>
>public goTest1 > >goTest1=createobject("nameparser") >goTest1.parse("Keith.,James Payne") > >define class nameparser as Custom olepublic > > cFullName = "" > cSalutation = "" > cFirstName = "" > cMiddleName = "" > cLastName = "" > cSuffix = "" > cSeparators = " .,;:" > nWords = 0 > > dimension aSalutation[11], aWords[1] > > hidden procedure init > with this > .aSalutation[1] = "MR" > .aSalutation[2] = "MRS" > .aSalutation[3] = "MS" > .aSalutation[4] = "DR" > .aSalutation[5] = "HON" > .aSalutation[6] = "REV" > .aSalutation[7] = "MISTER" > .aSalutation[8] = "MISSES" > .aSalutation[9] = "DOCTOR" > .aSalutation[10] = "HONORABLE" > .aSalutation[11] = "REVEREND" > endwith > endproc > > function parse(lcFullName as String) > > local i, lnNoSeparators, lcSeparator, lcWorkString, lnStart, lnLength > > lnNoSeparators = 0 > > with this > .cFullName = alltrim(lcFullName) >* for i = 1 to len(.cSeparators) >* lcSeparator = substr(.cSeparators,i,1) >* >* ** first replace each separator with a space and alltrim to remove any extra characters from the ends >* .cFullName = strtran(.cFullName,lcSeparator," ") >* .cFullName = alltrim(.cFullName) >* endfor * Comment out the above block, since it's equavelent to : .cFullName = chrtran(.cFullName,.cSeparator,replicate(space(1),len(.cSeparator)) > > if !empty(.cFullName) && make sure that the remaining string contains something > > ** now replace any instance of adjacent spaces with a single space > .cFullName = alltrim(strtran(.cFullName," "," ")) > > ? .cFullName > > lnNoSeparators = lnNoSeparators + occurs(" ", .cFullName) > ** There are lnNoSeparators+1 words in the name > .nWords = lnNoSeparators + 1 > > lcWorkString = .cFullName > dimension .aWords[.nWords] > > for i = 1 to .nWords > do case > case i = 1 > lnStart = 1 > lnLength = iif(at(" ",lcWorkString,i)>0,at(" ",lcWorkString,i)-1,len(lcWorkString))-(lnStart-1) > .aWords[i] = substr(lcWorkString,lnStart,lnLength) > case i = .nWords > lnStart = at(" ",lcWorkString,i-1)+1 > .aWords[i] = substr(lcWorkString,lnStart) > otherwise > lnStart = at(" ",lcWorkString,i-1)+1 > lnLength = (at(" ",lcWorkString,i)-1)-(lnStart-1) > .aWords[i] = substr(lcWorkString,lnStart,lnLength) > endcase > lcWorkString = alltrim(strtran(lcWorkString,.aWords[1],"")) > endfor > > do case > case .nWords = 1 > .aWords[1] = .cFullName > .cLastName = .cFullName > case .nWords = 2 > .cFirstName = left(.cFullName,at(" ",.cFullName)-1) > .cLastName = alltrim(strtran(.cFullName,.cFirstName,"")) > case .nWords = 3 > for i = 1 to alen(.aSalutation) > endfor > .cFirstName = left(.cFullName,at(" ",.cFullName)-1) > .cLastName = alltrim(strtran(.cFullName,.cFirstName,"")) > case .nWords = 4 > case .nWords > 4 > endcase > endif > endwith > endfunc >enddefine >>