文本文件处理,找一个一组数字中有某种规则的那种数字
ABCDABCDAAAB
AABB
ABABAB
AABAAB
ABCABC
上面是规则,比如
17855564562这组数字就符合aaab这个规则(178 5556 4562),这样找出来
比如13825625635,不符合abcabc这个规则(138 256 256 35)
希望大家指点,非常感谢。 --------------------编程问答-------------------- 需要把规则给定义一下,你的规则,就是表示相临的匹配模式。
比如 AAAB,前3个数字相同,第四个是前三个+1,
写个函数来判断这种规则:
--------------------编程问答-------------------- 呐......孔子曾经曰过,要提高结帖率 --------------------编程问答-------------------- 17855564562这组数字就符合aaab这个规则(178 5556 4562),这样找出来
public function chkStrRule(byval src as string,byval rule as string) as boolean
chkStrRule = false
dim i as long
if scr = "" or rule = "" then exit function
src = right(src,len(rule))
for i = 1 to len(rule)
mid(rule,i,1)=asc(mid(rule,i,1))-asc("A")+clng(mid(src,1,1))
next i
if rule=src then
chkStrRule = true
end if
end
aaab的正则表达式为(.)\1\1. 然后用正则去匹配,成功了就符合 --------------------编程问答-------------------- Public Const ABCDABCD As String = "01230123,12341234,23452345,34563456,45674567,56785678,67896789"
Public Const AAAB As String = "0001,1112,2223,3334,4445,5556,6667,7778,8889"
Public Const AABB As String = "0011,1122,2233,3344,4455,5566,6677,7788,8899"
Public Const ABABAB As String = "010101,121212,232323,343434,454545,565656,676767,787878,898989"
Public Const ABCABC As String = "012012,123123,234234,345345,456456,567567,678678,789789"
Public Function Patern_Match(ByRef Patern As String, ByVal Sample As String) As Boolean
Dim mPatern() As String
Dim i As Integer
mPatern = Split(Patern, ",")
For i = 0 To UBound(mPatern)
If InStr(1, Sample, mPatern(i)) Then
Patern_Match = True
Exit Function
End If
Next i
Patern_Match = False
End Function
---------------------------------------------
?patern_match(AAAB, "178 5556 4562")
True
?patern_match(ABCABC,"13825625635")
False
补充:VB , API