Sohail Zahid Sohail Zahid - 27 days ago 8
HTML Question

Change HTML values in JAVA (Android)

I have string value in

HTML
get web. Stored in varible
s
as shown below.

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


enter image description here

Problem

I want to change the width value
560
to
250
.

I try to use
s.replace("560", "250");
but its not working.

Any clues ...how can i change it.

Answer

This code works:

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);

If you print s you'll see 560 because Strings are immutable in java. If you don't want to declare a new String you could do in this way:

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);