简体   繁体   English

如何使用Java更改HTML文件的宽度和高度

[英]How to change the width and height of an html file using java

I wanted to change width="xyz" , where (xyz) can be any particular value to width="300". 我想更改width =“ xyz”,其中(xyz)可以是width =“ 300”的任何特定值。 I researched on regular expressions and this was the one I am using a syntax with regular expression 我研究了正则表达式,而这正是我使用的带正则表达式的语法

String holder = "width=\"340\"";
String replacer="width=\"[0-9]*\"";
theWeb.replaceAll(replacer,holder);

where theWeb is the string . 其中Web是字符串。 But this was not getting replaced. 但这并没有被取代。 Any help would be appreciated. 任何帮助,将不胜感激。

Your regex is correct. 您的正则表达式是正确的。 One thing you might be forgetting is that in Java all string methods do not affect the current string - they only return a new string with the appropriate transformation. 您可能会忘记的一件事是,在Java中,所有字符串方法都不会影响当前字符串-它们只会返回经过适当转换的新字符串。 Try this instead: 尝试以下方法:

String replacement = 'width="340"';
String regex = 'width="[0-9]*"';
String newWeb = theWeb.replaceAll(regex, replacement); // newWeb holds new text

Better use JSoup for manipulating and extracting data, etc. from Html 更好地使用JSoupHtml 处理和提取数据等

See this link for more details: 有关更多详细信息,请参见此链接:

http://jsoup.org/ http://jsoup.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM