javascript - 为什么在 node.js 中使用 split 时我得到 '+' 符号而不是 ','
问题描述
我有一个 .txt 文件,其中包含一些短语(拾取行),每个短语都在一个新行中。
这是一个样本
Does this rag smell like chloroform to you?
I have amnesia - do I come here often?
Your lips look lonely. Let me introduce them to mine
Your shirt has to go, but you can stay
我想创建一个数组,这样每一行都是这个数组中的一个元素。
所以我在节点上做了这个
const fs = require('fs')
let a = fs.readFileSync('database.txt', 'utf-8')
b = a.split('/n')
console.log(b)
但我得到的只是我的测试,行之间有一个加号。
解决方案
你必须用反斜杠'\n'分割行
b = a.split('\n')
推荐阅读
- amazon-web-services - 使用 Terraform 管理访问 RDS 数据库的凭据时出现问题
- sql-server - 从 2014 年升级到 SQL Server 2017 后受信任的程序集功能中断
- java - 按位表示为字节数组函数
- java - 在 springdoc 中禁用 JSR-303 注释处理
- c# - 如何从 UI c# 与正在运行的任务进行通信
- javascript - 单击传单标记时如何发送页面 URL?
- database - 从 .db 文件中获取数据
- javascript - 在拖动 jquery 可拖动 div 时显示指南并进行捕捉
- authentication - SQL 2016:连接到集群名称而不是单个节点时出现错误 18452
- python - plotly 不显示谷歌合作实验室中的情节