Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing unprintable characters in character and memo f
Message
From
09/12/2004 10:29:57
 
 
To
09/12/2004 10:17:45
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00967248
Message ID:
00968018
Views:
11
Claude,

>Thanks for the reply. I missunderstood your original posting and thought you were suggesting I create a variable to do all the replaces at once. I do have several questions on your code.
>
>1. Why do you use EVALUATE(taField) instead of macro substition of the vairable, i.e. is it faster?


Yes.

>
>2. Why call a function instead of using inline code?


I find it more readable and easier to code that way. Theoretically, inline code would probably be faster but I doubt the difference would be significant.

>
>
>>Claude,
>>
>>OK, I hadn't tested what I suggested and it had some problems. Here is some code I have tested that works. I'm not sure what characters you are eliminating so I just picked 2 at random and ran the following test program with a field in the table that has them plus a number of embedded spaces.
>>
>>#DEFINE BADCHARS CHR(128)+CHR(129)
>>#DEFINE ONE SPACE(1)
>>#DEFINE TWO SPACE(2)
>>
>>LOCAL lnFldCnt, lnPtr
>>LOCAL ARRAY laFields[1]
>>SET STEP ON
>>IF USED('Tran0')
>>   SELECT Tran0
>>ELSE
>>   USE Tran0
>>ENDIF
>>
>>lnFldCnt = AFIELDS(laFields)
>>
>>SCAN
>>
>>   FOR lnPtr = 1 TO lnFldCnt
>>      IF laFields[lnPtr,2] = 'C' OR ;
>>         laFields[lnPtr,2] = 'M'
>>         = Cleanup(laFields[lnPtr,1])
>>      ENDIF
>>   ENDFOR
>>
>>ENDSCAN
>>
>>FUNCTION Cleanup
>>LPARAMETERS taField
>>LOCAL lcString1, lcString2
>>
>>m.lcString1 = EVALUATE(taField)
>>
>>m.lcString2 = CHRTRAN(m.lcString1,BADCHARS,'')
>>
>>DO WHILE TWO $ m.lcString2
>>   m.lcString2 = STRTRAN(m.lcString2,TWO,ONE)
>>ENDDO
>>
>>IF LEN(ALLTRIM(m.lcString2)) < LEN(ALLTRIM(m.lcString1))
>>   REPLACE (taField) WITH m.lcString2
>>ENDIF
>>RETURN
>>
>>Hope this is a little more helpful!
Jim
Previous
Reply
Map
View

Click here to load this message in the networking platform