views:

62

answers:

3

var a

var a = "ACdA(a = %b, ccc= 2r2)";

var b

var b = "\ewfsd\ss.jpg"

Expected outputs:

var c = "ACdA(a = %b, ccc= 2r2, b_holder = \ewfsd\ss.jpg)"

It adds the string b to the end of string a, that's it! But be careful of the ")"

"b_holder " is hard coded string, it's absolutly same in all cases, won't be changed.

Thanks everyone!

A: 

You need to do two things:

  1. Concatenate ", b_holder = " to var b, and
  2. Replace ")" in var a with the result of the concatenation.

Since this is homework, I'll leave it to you to figure out which methods to use. Good luck!

Hint: you can either store the result of the concatenation in step (1) in another variable, or you can do it all in one line.

Edit: You also need to concatenate the ")" back onto the end. So maybe three things. :-)

No Surprises
A: 

You still don't show any code for what you're doing with a and b to produce c; you are just showing a simple assignment of the expected (desired) value.

You have a problem, however with the value you're assigning to var b -- because the backslash \ is an escape. If you want a backslash in the actual string you need to double it, so your assignment would be

var b = "\\ewfsd\\ss.jpg";
Stephen P
A: 
var a = "ACdA(a = %b, ccc= 2r2)";
var b = "\\ewfsd\\ss.jpg"; // need to escape the backslash for RegExp replace
var re = /\)$/;
var c = a.replace(re, ", b_holder = "+b+"\)");
ArtBIT