gpt4 book ai didi

java - 从 SDcard android 的 txt 文件中提取段落

转载 作者:行者123 更新时间:2023-12-01 13:49:28 25 4
gpt4 key购买 nike

我正在寻求帮助,因为我想从 adnroid 中 SD 卡的 .txt 文件中提取字符串段落。我有该文件,但无法提取其中的一部分。例如,我有这个文件:

Mother (mamá)Father (papá)Daughter (hija)Son (hijo)Sister (hermana)Brother (hermano)Grandmother (abuela)Grandfather (abuelo)Aunt (tia)Uncle (tio)Nephew (sobrino)Niece (sobrina)Cousin (primo "o" prima)Wife (esposa)Husband (esposo)NOTA: Al añadir las palabras inglesas "in law" se forman nuevas palabras que tambien deben ser incluidas en este vocabulario para referirnos a "La familia"Mother in law (*suegra)Father in law (*suegro)Sister in law (*cuñaada)Brother in law (*cuñado)gual sucede con la palabra "step" antepuesta a algunas palabras inglesas, para referirnos a otro parentesco familiar, resultado de la relacion de nuestros padres con otras parejas (como en el caso de divorcios,muerte de alguno de ellos,etc)Step mother (*madrastra)Step father (*padrastro)Step sister (*hermanastra)Step brother (*hermanastro)

and just nned to extracto from "Son" until "Niece"

my code is:

String state = Environment.getExternalStorageState();
TextView tv = (TextView) findViewById(R.id.textView1);
if (!estado.equals(Environment.MEDIA_MOUNTED)) {
tv.setText("No SDcard");
finish();
}

File dir = Environment.getExternalStorageDirectory();
File puntero = new File(dir.getAbsolutePath() + File.separator
+ "manualandroid.txt");
try {
Scanner lector = new Scanner(new FileReader(puntero));
StringBuilder texto = new StringBuilder();
String linea;
lv1 = (ListView) findViewById(R.id.listView1);
while (lector.hasNext()) {
linea = lector.nextLine();
if (linea.contains("Son") && linea.contains("Niece") {
texto.append(linea);
texto.append("\n");
}
}
lector.close();

} catch (IOException e) {
e.printStackTrace();
}

它只是向我显示包含“Son”和“Niece”的行,我对此很陌生。有人可以帮我请求吗?你需要阅读:

Son (hijo)Sister (hermana)Brother (hermano)Grandmother (abuela)Grandfather (abuelo)Aunt (tia)Uncle (tio)Nephew (sobrino)Niece (sobrina)

谢谢。

最佳答案

   int withinRange = -1;
while (lector.hasNext()) {
linea = lector.nextLine();

if (linea.contains("Son"))
withinRange =0;
if (withinRange == 0) {
texto.append(linea);
texto.append("\n");
}
if (linea.contains("Niece"))
withinRange = 1;
}

关于java - 从 SDcard android 的 txt 文件中提取段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20081712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com