2014-10-01 136 views
0

即時通訊設法搜索我的應用程序中的IconsGroup一些元素與「代碼」,使用TextInput和驗證是否包含組中的任何圖標的代碼。如何檢查TextInput是否有要在Flex中搜索的文本?

if(iconsGroup.numElements > 0) { 
    for(var i:int = 0; i<iconsGroup.numElements; i++) { 
    if(iconsGroup.getElementAt(i) is R_VO) { 
     if((iconsGroup.getElementAt(i) as R_VO)._extintores != null 
      && (txtBuscar.text.indexOf((iconsGroup.getElementAt(i) as R_VO)._extintores._codigo)) > -1) { 
    shake_AfterSearch(i); 
     } 
    } 
} 

但我的問題現在的問題是,如果我搜索文本:

「Code_1」

「CODE_1」

存在一種方法來搜索它並找到代碼爲「Code_1」或「CODE_1」的兩個圖標?,我想在不區分大小寫的情況下對其進行搜索

回答

2

您只需在字符串上使用toLowerCase()。在你的情況下,它會被看下一個:

var buscarText:String = txtBuscar.text.toLowerCase(); 
var searchedText:String; 

if(iconsGroup.numElements > 0) { 
    for(var i:int = 0; i<iconsGroup.numElements; i++) { 
    searchedText = (iconsGroup.getElementAt(i) as R_VO)._extintores._codigo.toLowerCase(); 
    if(iconsGroup.getElementAt(i) is R_VO) { 
     if((iconsGroup.getElementAt(i) as R_VO)._extintores != null 
      && (buscarText.indexOf(searchedText)) > -1) { 
      shake_AfterSearch(i); 
     } 
    } 
} 
+0

感謝您的答覆,但如果我保存代碼如「CoDe_1」發生了什麼? – NESTicle 2014-10-01 14:27:34

+1

當你使用「toLowerCase()」時,所有的字符都會在該字符串中被降低。 CoDe_1,CODE_1,code_1,cODE_1和類似的將轉到code_1。 – Crabar 2014-10-01 14:31:35

+0

知道了!,非常感謝你的幫助:) – NESTicle 2014-10-01 14:35:28

相關問題