| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1273 人关注过本帖
标题:关于搜寻相似字符串的问题
只看楼主 加入收藏
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
结帖率:97.66%
收藏
已结贴  问题点数:20 回复次数:7 
关于搜寻相似字符串的问题
111.rar (4.26 KB)

如果要将档案内的左边资料找出相似的PWR字符串~

相似的字符串的规则举例如下:
AAA=AAA_1 or AAA_BBB=AAA_BBB_1 or AAA_1=AAA_1_1
AAA_1_AAA<>AAA_1 or AAA_1_AAA<>AAA_2_AAA

不限定只有一组~每组不限定个数~要搜出来~
并且将左边字符串与右边对应数字存到结构中~
要怎么写比较好?

此档答案为:
图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: 字符串 资料 
2016-12-14 13:27
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:20 
AAA=AAA_1 or AAA_BBB=AAA_BBB_1
这二个规律,我理解为,右边字符串包含左边的字符串,并且位置从1开始。

AAA_1_AAA<>AAA_1 or AAA_1_AAA<>AAA_2_AAA
反之不成立。

不知是不是这样的。

s1 左,s2 右
if s1=left(s2,len(s1)) then  成立


授人于鱼,不如授人于渔
早已停用QQ了
2016-12-14 13:41
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
目前是这样写~求高手指正有没有BUG~或是有更适当的解法?
范本只附一个档案~但之后要扫将近4000个档案~

PowerPin()=>读入档案并处理过的资料
程序代码:
Private Sub AAA()

    .....
    .....

        For i = 0 To UBound(PowerPin)
            Status = False
            If i < UBound(PowerPin) Then
                If GetDPS(CH_Data_Count).SameCount > 0 Then
                    CH_Data_Count = CH_Data_Count + 1
                    ReDim Preserve GetDPS(CH_Data_Count)
                    GetDPS(CH_Data_Count).SameCount = 0
                    ReDim GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount)
                    ReDim GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount)
                End If

                For j = i + 1 To UBound(PowerPin)
                    If PowerPin(i) <> "" Then
                        If PowerPin(j) <> "" Then
                            If GetName(0, PowerPin(i)) = GetName(0, PowerPin(j)) Then
                                If GetDPS(CH_Data_Count).DPin(0) = "" Then
                              
                                    GetDPS(CH_Data_Count).DPin(0) = GetName(1, PowerPin(i))
                                    GetDPS(CH_Data_Count).Channel(0) = GetName(2, PowerPin(i))

                                    GetDPS(CH_Data_Count).SameCount = GetDPS(CH_Data_Count).SameCount + 1

                                    ReDim Preserve GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount) = GetName(1, PowerPin(j))
                                    ReDim Preserve GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount) = GetName(2, PowerPin(j))
                                Else
                                    GetDPS(CH_Data_Count).SameCount = GetDPS(CH_Data_Count).SameCount + 1

                                    ReDim Preserve GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount) = GetName(1, PowerPin(j))
                                    ReDim Preserve GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount) = GetName(2, PowerPin(j))
                                End If
                                Status = True: PowerPin(j) = ""
                            End If
                        End If
                    Else
                        Exit For
                    End If
                Next j
            End If
            If Status = True Then
                PowerPin(i) = ""
            End If
        Next i
      
        Erase PowerPin
      
        If GetDPS(CH_Data_Count).SameCount = 0 And GetDPS(CH_Data_Count).DPin(0) = "" And GetDPS(CH_Data_Count).Channel(0) = 0 Then
            ReDim Preserve GetDPS(CH_Data_Count - 1)
        End If

    .......
    .......

end Sub

Private Function GetName(Mode As Integer, PowerPin As String) As String
Dim Temp() As String, Temp1() As String

    GetName = ""
    Temp = Split(PowerPin, "=")
   
    If Mode = 0 Then
        If InStr(Temp(0), "_") <> 0 Then
            Temp1 = Split(Temp(0), "_")
            If IsNumeric(Temp1(UBound(Temp1))) = True Then
                For k = 0 To (UBound(Temp1) - 1)
                    GetName = GetName & Temp1(k) & "_"
                Next k
            Else
                For k = 0 To UBound(Temp1)
                    GetName = GetName & Temp1(k) & "_"
                Next k
            End If
            GetName = Mid$(GetName, 1, Len(GetName) - 1)
            Erase Temp1
        Else
            GetName = Temp(0)
        End If
    ElseIf Mode = 1 Then
        GetName = Trim$(Temp(0))
    ElseIf Mode = 2 Then
        GetName = Trim$(Temp(1))
    End If
   
    Erase Temp
   
End Function

不要選我當版主
2016-12-14 13:47
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
忘了附..

Private Type CH_Data
    Channel() As Integer
    DPin() As String
    SameCount As Integer
End Type

Dim GetDPS() As CH_Data, CH_Data_Count As Integer

不要選我當版主
2016-12-14 13:48
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
以下是引用风吹过b在2016-12-14 13:41:11的发言:

AAA=AAA_1 or AAA_BBB=AAA_BBB_1
这二个规律,我理解为,右边字符串包含左边的字符串,并且位置从1开始。
 
AAA_1_AAA<>AAA_1 or AAA_1_AAA<>AAA_2_AAA
反之不成立。
 
不知是不是这样的。
 
s1 左,s2 右
if s1=left(s2,len(s1)) then  成立
 

最后底线(前面也许也有多个底线串接)后为数字+底线前字符串皆相同 AAA_BBB_2=AAA_BBB_1 or AAA_1_BBB_2=AAA_1_BBB_1
最后底线后的字非数字则不符
若无底线(或最后没数字)但全部字和去掉最后底线后数字的字符串相同 AAA=AAA_1 or AAA_BBB=AAA_BBB_1 or AAA1=AAA1_1

感觉好乱~

不要選我當版主
2016-12-14 14:00
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
真是好乱。
那就只能先对左边预处理,如果最后是下划线+数字,设置一个标志,然后去掉这个部分生成用来测试用的左边
然后测试,如果通过,再检查这个标志,如果存在标志,那么判断右边是不是剩下2位,倒数2位是不是下划线,倒数1位是不是数字。

授人于鱼,不如授人于渔
早已停用QQ了
2016-12-14 19:00
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
以下是引用风吹过b在2016-12-14 19:00:29的发言:

真是好乱。
那就只能先对左边预处理,如果最后是下划线+数字,设置一个标志,然后去掉这个部分生成用来测试用的左边
然后测试,如果通过,再检查这个标志,如果存在标志,那么判断右边是不是剩下2位,倒数2位是不是下划线,倒数1位是不是数字。

这还只是第一步~后面还有一堆比对要做~反正写完了~也交差了~就看需求者确认结果有没有问题~
下面只是全部功能里面其中一小段~
程序代码:
Private Type CH_Data
    Channel() As Integer
    DPin() As String
    SameCount As Integer
End Type

Private Type DPS_Data
    PinChannel() As Integer
    V_Scale() As enDPS_V_SCALE
    I_Scale() As enDPS_I_SCALE
    I_ClampH() As Double
    I_Clamp_L() As Double
    Diff As Boolean
    DPS_Set_Name As String
End Type

Private Function Section2(FileName As String, NowStatus As String, MachineCat As String, Fab As String, Custom As String, Prod As String, KTPFileName As String, FullPath As String) As String
Dim GetDPS() As CH_Data, CH_Data_Count As Integer, CompareDPS() As DPS_Data, DPS_Data_Count() As Integer
Dim i As Integer, j As Integer, k As Integer, m As Integer, n As Integer
Dim DPSChnnel As Integer, DpsPinName As String, IScale As Double, IClamp As Double, IClampLow As Double
Dim TempStr As String, PowerPin() As String, Status As Boolean, DPSChannel As Integer, DPSSetName As String, Result As String
Dim No_Diff As Boolean

On Error GoTo aa

    i = 0: j = 0: k = 0: Status = False: TempStr = vbCrLf & vbCrLf & vbCrLf & KTPFileName & vbCrLf
    ReDim PowerPin(0): CH_Data_Count = 0: ReDim GetDPS(CH_Data_Count)
    GetDPS(CH_Data_Count).SameCount = 0: No_Diff = False
    ReDim GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount)
    ReDim GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount)
  
    With CompareProjectData(0)
  
        For i = 0 To .Device.PinNum - 1
            If .Device.PinData(i).TYPE = P_POWER Then
                ReDim Preserve PowerPin(j)
                PowerPin(j) = .Device.PinData(i).Name & "=" & .Device.PinData(i).DutChannel(0)
                j = j + 1
            End If
        Next i
      
        For i = 0 To UBound(PowerPin)
            Status = False
            If i < UBound(PowerPin) Then
                If GetDPS(CH_Data_Count).SameCount > 0 Then
                    CH_Data_Count = CH_Data_Count + 1
                    ReDim Preserve GetDPS(CH_Data_Count)
                    GetDPS(CH_Data_Count).SameCount = 0
                    ReDim GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount)
                    ReDim GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount)
                End If
                For j = i + 1 To UBound(PowerPin)
                    If PowerPin(i) <> "" Then
                        If PowerPin(j) <> "" Then
                            If GetName(0, PowerPin(i)) = GetName(0, PowerPin(j)) Then
                                If GetDPS(CH_Data_Count).DPin(0) = "" Then
                              
                                    GetDPS(CH_Data_Count).DPin(0) = GetName(1, PowerPin(i))
                                    GetDPS(CH_Data_Count).Channel(0) = GetName(2, PowerPin(i))
                                  
                                    GetDPS(CH_Data_Count).SameCount = GetDPS(CH_Data_Count).SameCount + 1

                                    ReDim Preserve GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount) = GetName(1, PowerPin(j))
                                    ReDim Preserve GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount) = GetName(2, PowerPin(j))
                                Else
                                    GetDPS(CH_Data_Count).SameCount = GetDPS(CH_Data_Count).SameCount + 1
                                  
                                    ReDim Preserve GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).DPin(GetDPS(CH_Data_Count).SameCount) = GetName(1, PowerPin(j))
                                    ReDim Preserve GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount)
                                    GetDPS(CH_Data_Count).Channel(GetDPS(CH_Data_Count).SameCount) = GetName(2, PowerPin(j))
                                End If
                                Status = True: PowerPin(j) = ""
                            End If
                        End If
                    Else
                        Exit For
                    End If
                Next j
            End If
            If Status = True Then
                PowerPin(i) = ""
            End If
        Next i
      
        Erase PowerPin
      
        If GetDPS(CH_Data_Count).SameCount = 0 And GetDPS(CH_Data_Count).DPin(0) = "" And GetDPS(CH_Data_Count).Channel(0) = 0 And CH_Data_Count <> 0 Then
            ReDim Preserve GetDPS(CH_Data_Count - 1)
        End If
      
        If GetDPS(0).SameCount = 0 And GetDPS(0).DPin(0) = "" And GetDPS(0).Channel(0) = 0 Then
            Exit Function
        End If
      
        For i = 0 To .DPSNum - 1
      
            ReDim DPS_Data_Count(UBound(GetDPS)): ReDim CompareDPS(0)
            DPSSetName = .DPS(i).Name
          
            For j = 0 To .DPS(i).StepNum - 1
                For k = 0 To .DPS(i).DPSStepCtrl(j).ChannelNum - 1
                    DPSChannel = .DPS(i).DPSStepCtrl(j).ChannelData(k).DPSChannel
                    For m = 0 To UBound(GetDPS)
                        For n = 0 To GetDPS(m).SameCount
                            If GetDPS(m).Channel(n) = DPSChannel Then
                                ReDim Preserve CompareDPS(m)
                              
                                ReDim Preserve CompareDPS(m).PinChannel(DPS_Data_Count(m))
                                CompareDPS(m).PinChannel(DPS_Data_Count(m)) = DPSChannel
                              
                                ReDim Preserve CompareDPS(m).V_Scale(DPS_Data_Count(m))
                                CompareDPS(m).V_Scale(DPS_Data_Count(m)) = .DPS(i).DPSStepCtrl(j).ChannelData(k).VScale
                              
                                ReDim Preserve CompareDPS(m).I_Scale(DPS_Data_Count(m))
                                CompareDPS(m).I_Scale(DPS_Data_Count(m)) = .DPS(i).DPSStepCtrl(j).ChannelData(k).IScale
                              
                                ReDim Preserve CompareDPS(m).I_ClampH(DPS_Data_Count(m))
                                CompareDPS(m).I_ClampH(DPS_Data_Count(m)) = .DPS(i).DPSStepCtrl(j).ChannelData(k).IClamp
                              
                                ReDim Preserve CompareDPS(m).I_Clamp_L(DPS_Data_Count(m))
                                CompareDPS(m).I_Clamp_L(DPS_Data_Count(m)) = .DPS(i).DPSStepCtrl(j).ChannelData(k).IClampLow
                              
                                DPS_Data_Count(m) = DPS_Data_Count(m) + 1
                              
                                CompareDPS(m).Diff = True
                                CompareDPS(m).DPS_Set_Name = DPSSetName
                            End If
                        Next n
                    Next m
                Next k
            Next j
          
            For j = 0 To UBound(CompareDPS)
                If CompareDPS(j).Diff = True Then
                    If UBound(CompareDPS(j).PinChannel) > 0 Then
                        For k = 0 To UBound(CompareDPS(j).PinChannel)
                            For m = k + 1 To UBound(CompareDPS(j).PinChannel)

                                If CompareDPS(j).V_Scale(k) <> CompareDPS(j).V_Scale(m) Or _
                                    CompareDPS(j).I_Scale(k) <> CompareDPS(j).I_Scale(m) Or _
                                    CompareDPS(j).I_ClampH(k) <> CompareDPS(j).I_ClampH(m) Or _
                                    CompareDPS(j).I_Clamp_L(k) <> CompareDPS(j).I_Clamp_L(m) Then
                                  
                                    Result = ""
                                    If CompareDPS(j).V_Scale(k) <> CompareDPS(j).V_Scale(m) Then
                                        Result = "V_Scale is Different"
                                    End If
                                  
                                    If CompareDPS(j).I_Scale(k) <> CompareDPS(j).I_Scale(m) Then
                                        If Result <> "" Then
                                            Result = Result & " & I_Scale is Different"
                                        Else
                                            Result = "I_Scale is Different"
                                        End If
                                    End If
                                  
                                    If CompareDPS(j).I_ClampH(k) <> CompareDPS(j).I_ClampH(m) Then
                                        If Result <> "" Then
                                            Result = Result & " & I_ClampH is Different"
                                        Else
                                            Result = "I_ClampH is Different"
                                        End If
                                    End If
                                  
                                    If CompareDPS(j).I_Clamp_L(k) <> CompareDPS(j).I_Clamp_L(m) Then
                                        If Result <> "" Then
                                            Result = Result & " & I_Clamp_L is Different"
                                        Else
                                            Result = "I_Clamp_L is Different"
                                        End If
                                    End If
                                  
                                    TempStr = TempStr & _
                                                CompareDPS(j).DPS_Set_Name & "," & _
                                                GetDPSPinName(CompareDPS(j).PinChannel(k)) & "," & _
                                                CompareDPS(j).V_Scale(k) & "," & _
                                                CompareDPS(j).I_Scale(k) & "," & _
                                                CompareDPS(j).I_ClampH(k) & "," & _
                                                CompareDPS(j).I_Clamp_L(k) & ",<>," & _
                                                GetDPSPinName(CompareDPS(j).PinChannel(m)) & "," & _
                                                CompareDPS(j).V_Scale(m) & "," & _
                                                CompareDPS(j).I_Scale(m) & "," & _
                                                CompareDPS(j).I_ClampH(m) & "," & _
                                                CompareDPS(j).I_Clamp_L(m) & "," & _
                                                Result & "," & FullPath & vbCrLf & vbCrLf
                                  
                                    No_Diff = True
                                  
'                                    Debug.Print TempStr
                                  
                                End If
                            Next m
                        Next k
                    End If
                End If
            Next j
        Next i
      
    End With
   

    If No_Diff = False Then
        TempStr = ""
    Else
        Call WriteInfo(TempStr)
    End If

Exit Function
aa:
    Resume Next
End Function

Private Function GetName(Mode As Integer, PowerPin As String) As String
Dim temp() As String, Temp1() As String

    GetName = ""
    temp = Split(PowerPin, "=")
  
    If Mode = 0 Then
        If InStr(temp(0), "_") <> 0 Then
            Temp1 = Split(temp(0), "_")
            If IsNumeric(Temp1(UBound(Temp1))) = True Then
                For k = 0 To (UBound(Temp1) - 1)
                    GetName = GetName & Temp1(k) & "_"
                Next k
            Else
                For k = 0 To UBound(Temp1)
                    GetName = GetName & Temp1(k) & "_"
                Next k
            End If
            GetName = Mid$(GetName, 1, Len(GetName) - 1)
            Erase Temp1
        Else
            GetName = temp(0)
        End If
    ElseIf Mode = 1 Then
        GetName = Trim$(temp(0))
    ElseIf Mode = 2 Then
        GetName = Trim$(temp(1))
    End If
  
    Erase temp
  
End Function

Private Sub WriteInfo(temp As String)
    Open "C:\DPS_Compare.csv" For Append As #1
        Print #1, temp
    Close #1
End Sub


不要選我當版主
2016-12-15 11:48
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
后段是透过我的程序去比对一个超大型结构体内的设定值~
我只能透露是跟半导体相关的系统程式~
一种IC就需要扫一次~所以有4000种IC设定~
就当我是暂存程序在这里吧~

不要選我當版主
2016-12-15 11:57
快速回复:关于搜寻相似字符串的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037996 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved