處理string list,stringlist

來源:互聯網
上載者:User

處理string list,stringlist

處理string list在一個string list中用Regex尋找

尋找第一個匹配到的元素:

> (set 'l '("WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the \log4j.properties files." "recommend" "search" "test"))("WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the log4j.prope\rties files."  "recommend" "search" "test")> (find "WARN" l 1)0> (find "WARN3" l 1)

注意,第三個參數用來表示用Regex尋找,1表示大小寫不敏感,0表示敏感。


用Regex尋找並刪除string list中的string

(context 'STRING_LIST);; @param case-insensitive 1 for case-insensitive search or 0 for no special options(define (remove str-list str-regex case-insensitive)  (do-while i    (begin      (set 'i (find str-regex str-list case-insensitive))      (if i      (pop str-list i))))  str-list  )



這樣下面的函數利用上面的函數將hive命令返回的string list中不需要的過濾掉,只剩下資料庫名稱。

;; @syntax (HIVE:show-dbs)                                                                                                                        (define (show-dbs)  (set 'r (exec (format "hive -e 'show databases' 2>&1")))  (set 'r (STRING_LIST:remove r "^WARNING.+" 1))  (set 'r (STRING_LIST:remove r "^Logging.+" 1))  (set 'r (STRING_LIST:remove r "^Hive.+" 1))  (set 'r (STRING_LIST:remove r "OK" 1))  (STRING_LIST:remove r "^Time taken.+" 1)  )


編寫程式處理一個string類型的list容器在該容器中尋找一個特殊值,如果找到,則將它刪除掉

你少了string的標頭檔肯定不行了,加上就可以了

#include <string>
 
List<List<String>> listlist; List<String> list; listlistadd(list); 報告null 指標異常,怎處理?

listlist 沒有賦值,
List<List<String>> listlist = new ArrayList<List<String>>();
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.