該文件使用\n
作爲行分隔符(不像標準Windows \r\n
)。 所以,只是不打開它與記事本或類似,與寫字板。
將文件加載到一個集合(讓它成爲HashSet<String>
- 你,也許,想測試一個詞是正話與否之內),您可以使用的Linq:
HashSet<String> positives = new HashSet<String>(File
.ReadLines(@"C:\positive-words.txt")
.Where(item => !String.isNullOrEmpty(item) && !item.StartsWith(";")));
....
String testWord = ...
if (positives.Contains(testWord)) {
...
}
實際文件的內容是
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Opinion Lexicon: Positive
...
; frequently in social media content.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a+
abound
abounds
abundance
...
zenith
zest
zippy