1

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.

2
  • have you escaped the double quotes ? like this "\"" Commented Nov 13, 2016 at 18:35
  • What actually happens ? what's the value of s after executing the previous line ? Commented Nov 13, 2016 at 18:37

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.