import java.util.*;
class ChangeCSS{
public static void main(String[] args){
System.out.println("Enter the Code to be converted to red css");
Scanner sc=new Scanner("System.in");
String str=sc.nextLine();
//Entered by user String str="<p style="text-align: center;">. <span class="text__white">Techno power</span></p>";
}
}
User inputs the above string
I am trying to update text__white to text__red
But inputing the above string in any String object is popping error
您可以在每个特殊字符前面使用正斜杠,如下所示 -
String str="<p style=\"text-align: center;\"><span class=\"text__white\">Techno power</span></p>";
I know the above answer corrects your String, but here's how you can replace the word text__white
with text__red
using the String.replace(String str1, String str2)
method:
public class ReplaceString {
public static void main(String[] args){
String str = "<p style=\"text-align: center;\"><span class=\"text__white\">Techno power</span></p>";
String strrep = str.replace("text__white", "text__red");
System.out.println(str);
System.out.println(strrep);
}
}
You can implement the required logic in your code from here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.