Java replace the string at the specified position in the string

Java replace the string at the specified position in the string

Use StringBuilder:

String str1="123456789你好.jpj";
		StringBuilder sb=new StringBuilder(str1);
		sb.replace(str1.length()-6, str1.length()-4, "nihao");
		String str2=sb.toString();
		System.out.println(str2);

Output result:

123456789nihao.jpj

Guess you like

Origin blog.csdn.net/qq_41915623/article/details/102458555