英文:
How can i make that everything after "," in .txt file will be checked separetly :)?
问题
我需要改进这段代码,它将从名为 file.txt
的文本文件中读取内容。
我想要使用以下形式:
file = login.getText();
if (file.equals("sergy"))
我只需要做一些能够将文本文件中的内容分别读取出来的操作,并忽略逗号“,”,或者除逗号“,”之外的其他内容。
英文:
I need to improve this code that will read from a text file named file.txt
>sergy,many,mani,kserder
I would like to use this form :
file = login.getText();
if (file.equals("sergy"))
I just need to do something that will read everything in the text file separately and ignoring "," sign, or something else other than "," sign.
答案1
得分: 1
你可以通过逗号字符,
来分割字符串,并检查数组中的任何元素是否等于你要查找的值:
file = login.getText();
if (Arrays.asList(file.split(",")).contains("sergy")) {
// 做些什么...
英文:
You could split the string by the ,
character and check if any of the array's elements are equal to the value you're looking for:
file = login.getText();
if (Arrays.asList(file.split(",")).contains("sergy")) {
// do something...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论