java - 在 JAVA (Android) 中更改 HTML 值

标签 java android html android-studio

我在 HTML get web 中有字符串值。存储在变量 s 中,如下所示。

<iframe width="560" height="315" src="https://www.youtube.com/embed/ubR8WfwQTkw" frameborder="0" allowfullscreen></iframe>

enter image description here

问题

我想将宽度值 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/

相关文章:

android - 是否有启用/禁用移动数据的 ADB 命令?( Root设备)

java - 从 Android 手机发送字符串到 PC

java - 如何使用Java访问不同机器(WIndows、linux等)上的hosts文件

java - 如何在最后一次出现下划线字符时将字符串拆分为 2

java - Apache Felix DOSGI 单一包和 Zookeeper

android - CountDownTimer 未在 onResume() 中启动

html - bootstrap cols 中字体大小的不同显示

html - 为什么 <select >'s value attribute doesn' t 设置 <select> 的值属性?

javascript - TypeError : $(. ..).SetHeight 不是函数

java - 关于unix下程序独立于命令行运行