{"id":798,"date":"2024-06-19T08:30:03","date_gmt":"2024-06-19T00:30:03","guid":{"rendered":"http:\/\/www.wyrcad.com\/?p=798"},"modified":"2025-02-05T11:39:35","modified_gmt":"2025-02-05T03:39:35","slug":"%e5%88%a4%e6%96%ad%e6%95%b0%e7%bb%84%e5%85%83%e7%b4%a0","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=798","title":{"rendered":"\u6570\u7ec4\u51fd\u6570\u7cfb\u5217\u4e4b\u4e00"},"content":{"rendered":"\n<p>Public Function IsInArray(ByVal sData As String, ByVal vData As Variant) As Boolean &#8216;\u67d0\u5b57\u7b26\u4e32\u662f\u5426\u5728\u67d0\u4e00\u7ef4\u6570\u7ec4\u4e2d<br>IsInArray = False<br>If Not IsArray(vData) Then Exit Function<br>If IsEmptyArray(vData) Then Exit Function<br>Dim I As Integer<br>For I = LBound(vData) To UBound(vData)<br>If sData = vData(I) Then IsInArray = True<br>Next I<br>End Function<\/p>\n\n\n\n<p>Public Function IsEmptyArray(ByVal sArray As Variant) As Boolean &#8216;\u5224\u65ad\u4e00\u7ef4\u6570\u7ec4\u4e3a\u7a7a\u6216\u8005\u5c1a\u672a\u521d\u59cb\u5316<br>&#8216;\u7c7b\u4f3c Dim TestArray(0 To 2) As String\uff0c\u4e00\u7ecf\u7533\u660e\uff0c\u5404\u5143\u7d20\u5373\u88ab\u8d4b &#8220;&#8221; \u503c\uff0cIsEmptyArray \u4e3a False\uff1b<br>&#8216;\u7c7b\u4f3c Dim TestArray() As String\uff0c\u867d\u7ecf\u7533\u660e\uff0c\u4ecd\u4e3a\u7a7a\u6570\u7ec4\uff0cIsEmptyArray \u4e3a True\u3002<br>Dim I As Integer, J As Integer<br>On Error GoTo ERR_EMPTY<br>I = UBound(sArray) &#8216;\u8bd5\u9519<br>If LBound(sArray) &gt; UBound(sArray) Then GoTo ERR_EMPTY<br>IsEmptyArray = False<br>On Error GoTo 0<br>Exit Function<br>ERR_EMPTY:<br>IsEmptyArray = True<br>On Error GoTo 0<br>End Function<\/p>\n\n\n\n<p>Public Function IndexInArray(ByVal sData As String, ByVal vData As Variant) As Integer &#8216;\u67d0\u6570\u503c\u5728\u67d0\u4e00\u7ef4\u6570\u7ec4\u4e2d\u7684\u4f4d\u6b21(\u4ee5\u6700\u5c0f\u53f7\u4e3a\u51c6, \u4e0d\u5b58\u5728\u5219\u4e3a -1)<br>Dim I As Integer, J As Integer<br>IndexInArray = -1<br>If Not IsArray(vData) Then Exit Function<br>If IsEmptyArray(vData) Then Exit Function<br>For I = LBound(vData) To UBound(vData)<br>If LCase(sData) = LCase(vData(I)) Then<br>IndexInArray = I<br>Exit For<br>End If<br>Next I<br>End Function<\/p>\n\n\n\n<p>Public Sub CleanUpArray(vData As Variant) &#8216;\u5254\u9664\u6570\u7ec4\u4e2d\u7684\u91cd\u590d\u6570\u636e<br>If Not IsArray(vData) Then Exit Sub &#8216;\u6570\u7ec4\u5224\u65ad<br>If IsEmptyArray(vData) Then Exit Sub<br>Dim LO, HI As Integer &#8216;\u4e0a\u4e0b\u754c<br>LO = LBound(vData)<br>HI = UBound(vData)<br>Dim I, J, KCount As Integer<br>KCount = 0 &#8216;\u8ba1\u6570\u5668<br>Dim DupeIndex() As String &#8216;\u91cd\u590d\u6570\u636e\u7684\u5e8f\u53f7\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u8bb0\u540e\u4e0d\u8bb0\u524d<br>For I = HI To LO Step -1<br>For J = I &#8211; 1 To LO Step -1<br>If vData(I) = vData(J) Then<br>KCount = KCount + 1<br>ReDim Preserve DupeIndex(1 To KCount) As String<br>DupeIndex(KCount) = CStr(I)<br>Exit For<br>End If<br>Next J<br>Next I<br>If KCount &gt; 0 Then &#8216;\u6709\u91cd\u590d<br>Dim iCount As Integer<br>iCount = LO &#8211; 1 &#8216;\u8ba1\u6570\u5668<br>Dim TempArray() As String<br>For I = LO To HI<br>If Not IsInArray(CStr(I), DupeIndex()) Then &#8216;\u9996\u6b21\u51fa\u73b0\u6216\u672a\u91cd\u590d\u7684\u6570\u636e<br>iCount = iCount + 1<br>ReDim Preserve TempArray(LO To iCount) As String<br>TempArray(iCount) = vData(I)<br>End If<br>Next I<br>ReDim vData(LO To iCount) &#8216; As String &#8216;\u91cd\u65b0\u8d4b\u503c\u5e76\u8fd4\u56de<br>For I = LO To iCount<br>vData(I) = TempArray(I)<br>Next I<br>Else<br>&#8216;\u65e0\u91cd\u590d\uff0c\u4e0d\u5904\u7406<br>End If<br>Erase DupeIndex<br>End Sub<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Public Function IsInArray(ByVal sData As String, ByVal  &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=798\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u6570\u7ec4\u51fd\u6570\u7cfb\u5217\u4e4b\u4e00\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,17],"class_list":["post-798","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=798"}],"version-history":[{"count":10,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/798\/revisions"}],"predecessor-version":[{"id":2228,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/798\/revisions\/2228"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}