javascript - 如何将一个字符串附加到另一个具有多行并由反斜杠字符终止的字符串
问题描述
我想将字符串变量附加到另一个字符串。第二个字符串包含大量字符,多行并由反斜杠字符(“\”)分隔。
我正在寻找 javascript 中的解决方案
例如
var one = 'test string one';
var two = 'test string two\
is seperated by back slash and this string has\
multiple number of lines';
现在我想将字符串一附加到字符串二,如下所示
var two = 'test string two'+one+\
is seperated by back slash and this string has\
multiple number of lines';
我正在寻找用第二个字符串附加第一个字符串。任何帮助,将不胜感激。
解决方案
您必须使用 a 再次开始字符串文字'
:
'test string two' + one + '\
is seperated by back slash and this string has\
multiple number of lines';
或者您使用模板字符串,那么您根本不需要换行符:
`test string two ${one}
is seperated by back slash and this string has
multiple number of lines`
推荐阅读
- c - 如何在C中打印循环链表中的所有节点
- python - 从python中的行中删除空格
- sql - 我使用 postgresql,我有一个这样的数据库
- node.js - 使用 AWS S3 在 node.js 应用程序中处理文件上传和存储
- java - 是否可以为其他未更改的项目设置使用修改后的 module-info.java 的 Maven 配置文件?
- jupyter-notebook - 使用 jupyter_client 时如何获取 HTML 中的数据?
- database - Firebase 可以生成 2 个相同的 ID 不区分大小写吗?
- c++ - 两个线程和一个类
- postgresql - Postgres Count Where ILIKE vs Postgres Count Where to_tsvector
- django - 在 Python Django 3.0.6 中使用“请求”库