首页 > 解决方案 > 我想更新其中包含双引号和分号的字符串数据

问题描述

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>";
  }
}

用户输入上述字符串

我正在尝试将 text__white 更新为 text__red

但是在任何 String 对象中输入上述字符串都会弹出错误

标签: javacollectionsstream

解决方案


您可以在每个特殊字符前面使用正斜杠,如下所示 -

String str="<p style=\"text-align: center;\"><span class=\"text__white\">Techno power</span></p>";

推荐阅读