找回密码
 加入
搜索
查看: 2631|回复: 2

[AU3基础] 【已解决】 比较两个字符串把相同和不相同的部分都列出来??

[复制链接]
发表于 2013-4-26 19:44:58 | 显示全部楼层 |阅读模式
本帖最后由 xdafeng 于 2013-4-26 21:18 编辑

比较两个字符串把相同和不相同的部分都列出来??
发表于 2013-4-26 21:08:46 | 显示全部楼层
你这个题目太大,搞不了,字符串比较的话,实在太多种情况了。
对于相对应位置上的比较:
$str1 = "123dsd456"
$str2 = "123456abc"

MsgBox(0, "", compare($str1, $str2))

Func compare($s1, $s2)
        Local $l1 = StringLen($s1)
        Local $l2 = StringLen($s2)
        Local $dstr1, $dstr2
        Local $sstr
        If BitAND($l1, $l2) = 0 Then SetError(0)
        If $l1 = $l2 Then
                For $i = 1 To $l1
                        If StringCompare(StringMid($s1, $i, 1), StringMid($s2, $i, 1)) = 0 Then
                                $sstr = $sstr & StringMid($s1, $i, 1)
                        Else
                                $dstr1 = $dstr1 & StringMid($s1, $i, 1)
                                $dstr2 = $dstr2 & StringMid($s2, $i, 1)
                        EndIf
                Next
        ElseIf $l1 < $l2 Then
                For $i = 1 To $l1
                        If StringCompare(StringMid($s1, $i, 1), StringMid($s2, $i, 1)) = 0 Then
                                $sstr = $sstr & StringMid($s1, $i, 1)
                        Else
                                $dstr1 = $dstr1 & StringMid($s1, $i, 1)
                                $dstr2 = $dstr2 & StringMid($s2, $i, 1)
                        EndIf
                Next
                $dstr2 = $dstr2 & StringMid($s2, $l1 + 1)
        ElseIf $l1 > $l2 Then
                For $i = 1 To $l2
                        If StringCompare(StringMid($s1, $i, 1), StringMid($s2, $i, 1)) = 0 Then
                                $sstr = $sstr & StringMid($s2, $i, 1)
                        Else
                                $dstr1 = $dstr1 & StringMid($s1, $i, 1)
                                $dstr2 = $dstr2 & StringMid($s2, $i, 1)
                        EndIf
                Next
                $dstr1 = $dstr1 & StringMid($s1, $l2 + 1)
        EndIf
        Return "The Same String :" & $sstr & @CRLF & "The Different String :" & $dstr1 & "<==>" & $dstr2
EndFunc   ;==>compare

如果不是相对应位置上的比较,那么用StringInStr,还要考虑到把其中一个字符串拆开。
拆开还要考虑:一个一个拆开,两个两个拆开……N个N个拆开……。
拿"12345678”举例,两个两个拆开,还要考虑到又分为
(一):12,34,56,……
(二):12,23,34,……
太麻烦,题目太大,楼主根据自己的要求再细化考虑一下吧。~
 楼主| 发表于 2013-4-26 21:17:19 | 显示全部楼层
谢谢!!就要这种效果
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-29 05:27 , Processed in 0.090121 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表