Hello everyone, there is such a search code:
//считываем текст с файла AssetManager am = getAssets(); InputStream is = am.open("file.txt"); ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) != -1) { result.write(buffer, 0, length); } String xxx = result.toString("UTF-8"); is.close(); //ищем и выводим строки по паттерну String reg = String.format("(.*)(%s)(.*)", edittext.getText().toString()); textview.setText(""); String[] mf = xxx.split(System.getProperty("line.separator")); for (String str : mf) if (Pattern.matches(reg, str)) textview.setText(textview.getText()+str+"\n");
I can’t understand why, stupidly, when reading text from a file, it does not look for regularity matches in it, but if you create, say, String xxx = new String("A\nB\nC");
then everything works fine. I tried to change the encoding, methods of reading from the file, but still it normally creates an array, but does not find matches (or only in the last line).
Do not tell me what is wrong?
xxx
read the contents of a file? - Vladyslav Matviienko