Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Possible bug
Message
De
27/12/2001 17:17:45
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00598533
Message ID:
00598591
Vues:
35
Thanks for the info and especially thank you for the code :)

- Keith

>Hi Keith,
>
>Sounds like a bug to me, though I don't have VFP7 to test. However, you can use Foxtools function REDUCE() to reduce all spaces to just one.
>
>Download Foxtools help file by George Tasker from Download section here.
>
>BTW, I didn't know, what you can set Init to be hidden.
>
>I also made some little enchancement in your code, see inside:
>
>>When running the code at the bottom of this message, the following statement:
>>
.cFullName = alltrim(strtran(.cFullName,"  "," "))
>>...does not strip out both occurences of " " (two adjacent spaces).
>>
>>In the command window it does strip out both occurences when run with a literal and a memvar:
>>
>>
>>? strtran("Keith  James  Payne","  "," ")
>>
>>lcTest = "Keith  James  Payne"
>>? strtran(lcTest,"  "," ")
>>
>>
>>Both of the preceeding ? statements produce the correct result "Keith James Payne".
>>
>>Also in the following program it works correctly:
>>
>>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
>>
>>
>>Here is the complete class definition (which does not work):
>>
>>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
>>
>>
>>I am running VFP7, version 07.00.0000.9262.
>>
>>Have I missed something or is this a bug?
>>
>>- Keith Payne
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform