简体   繁体   English

在单引号内串联的两个变量

[英]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 我有一个名为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... 我从该文件中获取了值http://www.xyzftp/myservice/service1.svc 。现在,我需要使用它连接/ logincheck并将其作为URL传递给ajax调用...

Thats my specific need guys !! 多数民众赞成在我的具体需要的家伙!

Any ideas friends ??? 有什么想法的朋友吗?

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() : 要连接两个字符串,只需用+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'"

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 ' 您将获得字符串:“ http://www.xyzftp/myservice/service1.svc/logincheck

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

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

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