如何在JavaScript中的第一个字符串中添加两个带有空格的字符串?
要添加两个字符串,我们需要一个'+'运算符来在字符串之间创建一些空间,但是当第一个字符串本身包含空格时,就无需显式分配空间。
在下面的示例中,由于字符串'str1'中包含空格,因此仅串联 而没有空格就足以添加两个字符串。
示例
<html>
<body>
<script>
function str(str1, str2) {
return (str1 + str2);
}
document.write(str("tutorix is the best ","e-learning platform"));
</script>
</body>
</html>输出结果
tutorix is the best e-learning platform
如果第一个字符串中没有空格,则必须创建space(“”)并将两个字符串连接起来,如下所示。
示例
<html>
<body>
<script>
function str(str1, str2) {
return (str1 + " " + str2);
}
document.write(str("tutorix is the best","e-learning platform"));
</script>
</body>
</html>输出结果
tutorix is the best e-learning platform
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短