public String ReturnStr(String m1, String m2, String text, int startIndex) { int first, second; //Π½Π΅ ΡΠ°Π±ΠΎΡΠ°Π΅ΠΌ Ρ ΠΏΡΡΡΡΠΌΠΈ ΡΡΡΠΎΠΊΠ°ΠΌΠΈ if(m1.length() == 0 || m2.length() == 0 || text.length() == 0) return null; //ΠΏΡΠΎΠ²Π΅ΡΠΈΠΌ, Π½Π΅ Π²ΡΡ
ΠΎΠ΄ΠΈΡ Π»ΠΈ ΡΡΠ°ΡΡΠΎΠ²ΡΠΉ ΠΈΠ½Π΄Π΅ΠΊΡ Π·Π° ΠΏΡΠ΅Π΄Π΅Π»Ρ ΡΠ΅ΠΊΡΡΠ° if( startIndex < 0 || startIndex > text.length()) return null; //Π½Π°Ρ
ΠΎΠ΄ΠΈΠΌ ΠΏΠ΅ΡΠ²ΡΡ ΠΌΠ΅ΡΠΊΡ ΠΈ ΡΠ΄Π²ΠΈΠ³Π°Π΅ΠΌ ΠΈΠ½Π΄Π΅ΠΊΡ Π½Π° Π΄Π»ΠΈΠ½Ρ ΠΌΠ΅ΡΠΊΠΈ first = text.indexOf(m1,startIndex); //Π΅ΡΠ»ΠΈ Π½Π°ΡΠ°Π»ΡΠ½ΠΎΠΉ ΠΌΠ΅ΡΠΊΠΈ Π½Π΅ Π½Π°ΡΠ»ΠΎΡΡ, Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΠΌ null //Π½ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡΡ 2 ΡΡΡΠΎΠΊΠΈ Π½ΠΈΠΆΠ΅ ΠΈ Π²Π΅ΡΡΠΈ ΠΎΡΡΡΠ΅Ρ Ρ Π½Π°ΡΠ°Π»Π° ΡΠ΅ΠΊΡΡΠ°, ΡΡΠΎ ΠΏΠΎ ΠΆΠ΅Π»Π°Π½ΠΈΡ if(first < 0)return null;// Π·Π°ΠΌΠ΅Π½ΠΈΡΡ ΡΡΡ ΡΡΡΠΎΠΊΡ first += m1.length();// ΠΈ ΡΡΡ Π½Π° if(first < 0) first = 0; //ΠΏΡΠΎΠ²Π΅ΡΠΈΠΌ, Π½Π΅ ΡΠ²Π»ΡΠ΅ΡΡΡ Π»ΠΈ ΠΌΠ΅ΡΠΊΠ° ΠΊΠΎΠ½ΡΠΎΠΌ ΡΠ΅ΠΊΡΡΠ° if(first >= text.length()) return null; //Π½Π°Ρ
ΠΎΠ΄ΠΈΠΌ Π²ΡΠΎΡΡΡ ΠΌΠ΅ΡΠΊΡ second = text.indexOf(m2, first); //Π΅ΡΠ»ΠΈ Π½Π°ΡΠ»ΠΈ ΡΠΎΠ»ΡΠΊΠΎ Π½Π°ΡΠ°Π»ΡΠ½ΡΡ ΠΌΠ΅ΡΠΊΡ, Π²ΡΡΠ΅Π·Π°ΡΡ Π²Π΅ΡΡ ΡΠ΅ΠΊΡΡ Π΄ΠΎ ΠΊΠΎΠ½ΡΠ° if(second < 0)return text.substring(first); return text.substring(first, second); }
Search by any given tags. In general, there is a lot to improve here, it depends on the problem to be solved.