Is it possible in Java to find the N number (user input) entry under the lines, and only replace it if it is, and not change all the text.
Suppose you entered the string pppooopppooocccpppbb , look for the value of ооо inside and change it to ddd , but for now the program changes all the text to ooo
public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Введите текст: "); String s = scan.nextLine(); System.out.println("Введенный текст: "+s); System.out.print("Введите искомую строку: "); String str1 = scan.nextLine(); System.out.print("Введите заменяющую строку: "); String str2 = scan.nextLine(); s=s.replaceAll(str1, str2); System.out.println(s); }
replaceAll(All, dare) if you need to change one entry? - ArchDemonpppdddpppdddcccpppbbfor me, was it expected? Add the result you want to see. - MrFylypenko