以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  字典匹配如何忽略字母大小写?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=68216)

--  作者:wh420
--  发布时间:2015/5/12 15:42:00
--  字典匹配如何忽略字母大小写?

Dim dic As new Dictionary(of String,String)
Dim dicfile As String =  Forms("窗口1").Controls("TextBox2").value
Dim Book As New XLS.Book(dicfile)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
For i As Integer = 0 To Sheet.Rows.Count-1
    If dic.ContainsKey(Sheet(i, 0).Text) = False Then
        dic.add(Sheet(i, 0).Text,Sheet(i, 1).Text)
    End If
Next

 

If dic.ContainsKey(Sheet1(i, j).Text) Then
  Sheet1(i, j).Value = Sheet1(i, j).Text & "|" & dic(Sheet1(i, j).Text)
end if


字典:键为:BUS BAY  值为:巴士站
需要匹配的EXCEL文件内容为:
1行1列:BUS BAY
2行1列:Bus BAY
3行1列:bus bay


只有1行1列的那个全部大写的(BUS BAY)能匹配上,其他小写及大小写混合的就匹配不上
问:字典如何忽略大小写?使以上3行内容全部匹配?


--  作者:Bin
--  发布时间:2015/5/12 15:43:00
--  
 If dic.ContainsKey(Sheet(i, 0).Text.toUpper) = False Then
        dic.add(Sheet(i, 0).Text.toUpper,Sheet(i, 1).Text.toUpper)
    End If
--  作者:wh420
--  发布时间:2015/5/12 15:51:00
--  
.toUpper只匹配大写的,小写的及大小写混合的就不行了。我要的是不管键是大写的BUS BAY还是小写的bus bay还是混合的 Bus Bay 都可以匹配
--  作者:Bin
--  发布时间:2015/5/12 15:52:00
--  
呵呵,用了就知道.没有问题. 全部都转为大写了
--  作者:wh420
--  发布时间:2015/5/12 15:54:00
--  
试过了不行,您上面的语句等于把字典中的键都改为大写了,但我需要与之匹配的EXCEL有小写,有混合
--  作者:大红袍
--  发布时间:2015/5/12 15:58:00
--  

全部弄成大写不就行了?

 

Dim dic As new Dictionary(of String,String)
Dim dicfile As String =  Forms("窗口1").Controls("TextBox2").value
Dim Book As New XLS.Book(dicfile)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
For i As Integer = 0 To Sheet.Rows.Count-1
    If dic.ContainsKey(Sheet(i, 0).Text.ToUpper) = False Then
        dic.add(Sheet(i, 0).Text.ToUpper,Sheet(i, 1).Text)
    End If
Next

 

If dic.ContainsKey(Sheet1(i, j).Text.ToUpper) Then
  Sheet1(i, j).Value = Sheet1(i, j).Text & "|" & dic(Sheet1(i, j).Text)
End If

 


--  作者:wh420
--  发布时间:2015/5/12 16:07:00
--  
TO 大红袍,试过了提示给定的关键字不在字典中。
--  作者:大红袍
--  发布时间:2015/5/12 16:08:00
--  

 这句忘记改了

 

Sheet1(i, j).Value = Sheet1(i, j).Text & "|" & dic(Sheet1(i, j).Text.ToUpper)


--  作者:wh420
--  发布时间:2015/5/12 16:21:00
--  
问题解决,多谢大红袍