我在 HTML
get web 中有字符串值。存储在变量 s
中,如下所示。
<iframe width="560" height="315" src="https://www.youtube.com/embed/ubR8WfwQTkw" frameborder="0" allowfullscreen></iframe>
问题
我想将宽度值 560
更改为 250
。
我尝试使用 s.replace("560", "250");
但它不起作用。
任何线索......我该如何改变它。
最佳答案
此代码有效:
String s = "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/ubR8WfwQTkw\" frameborder=\"0\" allowfullscreen></iframe>";
String replace = s.replace("560", "250");
System.out.println(replace);
如果您打印 s
,您将看到 560
,因为字符串在 java 中是不可变的。如果你不想声明一个新的字符串,你可以这样做:
String s = "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/ubR8WfwQTkw\" frameborder=\"0\" allowfullscreen></iframe>";
s = s.replace("560", "250");
System.out.println(s);
关于java - 在 JAVA (Android) 中更改 HTML 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40577340/