Legolas
Legolas

Reputation: 163

Two variables concatenated inside single quotes

I have went through many samples to have a variable inside quotes..But that doesnt help my case..it is strange in my case..have a look at it..

Var x='http://www.xyzftp/myservice/service1.svc'

Var y='/logincheck'

Now i want to have it inside a single quoted string like

'http://www.xyzftp/myservice/service1.svc/logincheck'

UPDATE:

I have a file named domainname.xml

I get the value http://www.xyzftp/myservice/service1.svc from that file.Now i need to concatenate /logincheck with it and pass as an URL to an ajax call...

Thats my specific need guys !!

Any ideas friends ???

Upvotes: 1

Views: 4868

Answers (3)

keithjgrant
keithjgrant

Reputation: 12739

There is no difference between a variable declared with single quotes vs. one declared with double quotes:

var a = 'test';
var b = "test";
a === b;
> true

To join your two strings, just concatenate them with a + or concat():

var x='http://www.xyzftp/myservice/service1.svc';
var y='/logincheck';

var z = x + y; // concat with +    
z;
> "http://www.xyzftp/myservice/service1.svc/logincheck"

// or

var z = x.concat(y); // concat with contact()
z;
> "http://www.xyzftp/myservice/service1.svc/logincheck"

Now, if we're all just misunderstanding your question, and what you are actually looking for is a string with single quotes as part of the string contents, here's how you can get that:

var x='http://www.xyzftp/myservice/service1.svc';
var y='/logincheck';
var z = "'" + x + y + "'"; // use double quotes as string delimiters
// or:
var z = '\'' + x + y + '\''; // use single quotes as delimiters and
                           // escape the single quote in the string
z;
> "'http://www.xyzftp/myservice/service1.svc/logincheck'"

Upvotes: 1

Evan Hahn
Evan Hahn

Reputation: 12712

var x = 'http://www.xyzftp/myservice/service1.svc';
var y = '/logincheck';
var combined = x + y;

Upvotes: 0

sourcecode
sourcecode

Reputation: 1802

do like this:

Var x='http://www.xyzftp/myservice/service1.svc'

Var y='/logincheck'

x= x+""+y;  or simply x= x+y;

you will get string: 'http://www.xyzftp/myservice/service1.svc/logincheck'

Upvotes: 0

Related Questions