简体   繁体   English

我怎样才能使“,” in.txt 文件之后的所有内容都将被单独检查:)?

[英]How can i make that everything after “,” in .txt file will be checked separetly :)?

I need to improve this code that will read from a text file named file.txt我需要改进将从名为file.txt的文本文件中读取的代码

sergy,many,mani,kserder sergy,许多,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.我只需要做一些事情,分别读取文本文件中的所有内容并忽略“,”符号或“,”符号以外的其他内容。

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...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 txt 文件中获取数据并将其发送到 Excel 电子表格?(我只想要 txt 文件中“:”之后的所有内容)? - How do i get data from a txt file and send it to excel spreadsheet?(I only want everything after the “:” in the txt file)? 如何使DataOutputStream将布尔或整数写入txt文件? - How can I make DataOutputStream write a bool or integer to a txt file? 从.txt文件中读取名称后,如何打印下3行? - How can I print the next 3 lines after reading a name from a .txt file? 我如何使自己的复选框处于选中状态 - How can i make my checkbox checked by itself 附加.txt文件会清除所有内容 - Appending .txt file is erasing everything 我如何使用 trim() 方法来完成这项工作? 我需要读取txt文件,同时忽略空行和以“//”开头的行 - how can i use the trim() method to make this work? I need to read the txt file while ignoring the blank line and lines that start with "//" 我如何使这个 If 语句适用于所有内容? - How do I make this If statement work with everything? 如何在Android Studio中导入和使用txt文件? - How can I import, and use txt file in Android Studio? 如何从.txt文件读取随机文本? - How can I read random text from .txt file? 如何从txt文件中读取2行 - How Can I Read 2 lines From txt File
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM