简体   繁体   English

验证字符串/字符数据中的循环/逻辑问题

[英]loop/logic issues in validating string/character data

I need to see if the characters at the end of a string are a zip code or zip+4.我需要查看字符串末尾的字符是 zip 代码还是 zip+4。 If there is no zip or zip+4 at the end of this string, then this address is rejected.如果此字符串的末尾没有 zip 或 zip+4,则拒绝此地址。 I don't understand why when I get to the dash character, "-", which is asci 45, my noZip becomes TRUE right here.我不明白为什么当我到达破折号字符“-”(即 asci 45)时,我的 noZip 在这里变成了 TRUE。 I am returning a "Yes" from the fnIsDash function, but I leave the loop at that point.我从 fnIsDash function 返回“是”,但此时我离开了循环。

Related to this problem -- I would like to use a regular expression to see if my string is a zip code, it would be "NNNNN-NNNN" or "NNNNN" where N is any digit.与此问题相关——我想使用正则表达式来查看我的字符串是否为 zip 代码,它将是“NNNNN-NNNN”或“NNNNN”,其中 N 是任何数字。 But from my research, I didn't see robust regular expression functionally in Progress.但是根据我的研究,我没有看到功能强大的正则表达式在进行中。 Is that true?真的吗?

FUNCTION fnisNumeric RETURNS LOGICAL (INPUT cCharacter AS CHARACTER) FORWARD.
FUNCTION fnisDash RETURNS LOGICAL (INPUT cCharacter AS CHARACTER) FORWARD.

DEFINE VARIABLE location AS CHARACTER NO-UNDO.
DEFINE VARIABLE zipPlus4Temp AS CHARACTER NO-UNDO.
DEFINE VARIABLE noZip AS LOGICAL NO-UNDO.
DEFINE VARIABLE cThisChar AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTemp AS CHARACTER NO-UNDO.
DEFINE VARIABLE iTemp AS INTEGER NO-UNDO.

location = "124 State Road Mechanicsburg PA 17050-3156".

zipPlus4Temp = SUBSTRING (location, length(location) - 9, 10).
MESSAGE "zipPlus4Temp " + zipPlus4Temp VIEW-AS ALERT-BOX.
noZip = FALSE.
                                                                           
DO iTemp = 1 TO LENGTH(zipPlus4Temp):
   IF noZip EQ TRUE THEN LEAVE.
       cThisChar = SUBSTRING(zipPlus4Temp,iTemp,1).
       MESSAGE STRING(iTemp) + " this char " + cThisChar VIEW-AS ALERT-BOX.
       IF iTemp GE 1 AND iTemp GE 5 THEN
           IF NOT(fnIsNumeric(cThisChar)) THEN noZip = TRUE.
       //noZip becomes true here
       IF iTemp EQ 6 THEN 
           IF NOT(fnIsDash(cThisChar)) THEN noZip = TRUE.
       IF iTemp GE 7 AND iTemp GE 10 THEN 
           IF NOT(fnIsNumeric(cThisChar)) THEN noZip = TRUE. 
END.

MESSAGE SUBSTITUTE("zipPlus4Temp &1 is &2",zipPlus4Temp, noZip).

FUNCTION fnIsNumeric RETURNS LOGICAL (i_cc as CHARACTER):
    RETURN ASC(i_cc) GE 48 AND ASC(i_cc) LE 57.
END FUNCTION.

FUNCTION fnIsDash RETURNS LOGICAL (i_cc as CHARACTER):
    MESSAGE SUBSTITUTE("The character being passed is &1",i_cc) VIEW-AS ALERT-BOX.
    MESSAGE "the ascii value of the character being passed is " + STRING(ASC(i_cc)) VIEW-AS ALERT-BOX.
    RETURN ASC(i_cc) EQ 45.
END FUNCTION.

Your noZip variable is becoming TRUE before the dash check.您的 noZip 变量在破折号检查之前变为 TRUE。 You have an error in your digit 1-5 logic.您的数字 1-5 逻辑有误。 The IF-THEN statement says greater than or equal to 1 and greater than or equal to 5. It should be less than or equal to 5. Change the line to this: IF-THEN 语句表示大于或等于 1 且大于或等于 5。它应该小于或等于 5。将行更改为:

IF iTemp GE 1 AND iTemp LE 5 THEN

Same for the digit 7-10 check, but that isn't affecting the noZip value.数字 7-10 检查相同,但这不会影响 noZip 值。

IF iTemp GE 7 AND iTemp LE 10 THEN

And no, Progress doesn't support regular expressions.不,Progress 不支持正则表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM