连接两个字符串,并用逗号和空格隔开 [英] Joining two strings with a comma and space between them
本文介绍了连接两个字符串,并用逗号和空格隔开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了两个字符串 str1
和 str2
,我需要将它们加入一个字符串。结果应该是这样的: String1,String 2
。 str1
和 str2
变量没有,
。
I have been given the two strings "str1"
and "str2"
and I need to join them into a single string. The result should be something like this: "String1, String 2"
. The "str1"
and "str2"
variables however do not have the ", "
.
现在要问的问题:如何在用逗号和空格分隔字符串的同时连接这些字符串?
So now for the question: How do I join these strings while having them separated by a comma and space?
这是我看到任务时想出的结果,它不会与,
分开,结果是
This is what I came up with when I saw the "task", this does not seperate them with ", "
though, the result for this is "String2String1".
function test(str1, str2) {
var res = str2.concat(str1);
return res;
}
推荐答案
尝试一下:
function test(str1, str2) {
var res = str2 + ',' + str1;
return res;
}
这篇关于连接两个字符串,并用逗号和空格隔开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文