2013-02-27 2 views
0

잠시 동안 Visual FoxPro를 사용하지 않았습니다. 오늘 전 동료가 이름 필드에서 비 문자를 제거하는 방법을 묻습니다. 즉 a-z 및 A-Z 만 허용됩니다. 나는 strstran이라는 함수를 사용하여이 작업을 수행했다는 것을 기억합니다. a-z와 A-Z를 포함하는 변수를 정의해야했습니다. 하지만 지금은 기억이 안납니다. 누군가이 문제를 처리하는 방법을 알고 있습니까? 미리 감사드립니다.Visual FoxPro를 사용하여 이름 필드에서 비 문자 문자를 제거하는 방법

답변

5

CHRTRAN() 함수를 사용하십시오.

FUNCTION GetAlphaCharacters 
    LPARAMETERS tcExpressionSearched 

    LOCAL lcAllowedCharacters 
    m.lcAllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 

    RETURN CHRTRAN(m.tcExpressionSearched, CHRTRAN(m.tcExpressionSearched, m.lcAllowedCharacters, ""), "") 
ENDFUNC 
0

또 다른 옵션은 ISALPHA()를 사용하는 것입니다. 이것은 문자열의 가장 왼쪽 위치 만 보지만 대소 문자를 구분하지는 않습니다.

***This should work, but I haven't tested it. 
myresults = "" 
myvar = "MyText12" 
FOR(i = 1 TO LEN(myvar)) 
    IF ISALPHA(SUBSTR(myvar, i, 1)) 
    myresults = myresults + SUBSTR(myvar, i, 1) 
    ENDIF 
ENDFOR 
RETURN myresults 
0

나는 파티에 좀 늦다는 것을 알고있다.하지만 여기서는 인쇄 할 수없는 모든 ASCII 문자를 문자열에서 지우는 기능이있다.

CLEAR 

    * Contains ASCII characters 1 (SOH) and 2 (STX) 
    cTest = "Garbage Data "  

    ? cTest 
    cTest = RemoveNonPrintableCharacters(cTest) 
    ? cTest 


    FUNCTION RemoveNonPrintableCharacters 
     LPARAMETERS tcExpressionSearched 

     cCleanExpression = tcExpressionSearched 

     * Cleans out the first 32 ASCII characters, which are not printable 
     FOR decCount = 0 TO 31 
      cCleanExpression = CHRTRAN(m.cCleanExpression, CHR(decCount), "")  
     ENDFOR 

     * Also cleans out the non-printable DEL character (ASCII 127) 
     cCleanExpression = CHRTRAN(m.cCleanExpression, CHR(127), "") 

     * Return the clean string 
     RETURN cCleanExpression 
    ENDFUNC 
관련 문제