如何通过JavaScript中的换行符从字符串创建数组? [英] How to make an array from a string by newline in JavaScript?

查看:128
本文介绍了如何通过JavaScript中的换行符从字符串创建数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

var quoted_text = window.getSelection;

var quoted_text = window.getSelection;

例如:


接受服务条款

Accepting the Terms of Service

堆叠交换网络(网络) )是一组相关的
互联网站点和其他问题和答案的应用程序,拥有
并由Stack Exchange Inc.(Stack Exchange)运营,这是一家特拉华州
公司。在使用网络或
网络上提供的任何服务(统称为服务)之前,请仔细阅读这些服务条款(协议)
。使用或访问
服务,即表示您同意遵守本协议
的所有条款和条件。如果您不同意本协议
的所有条款和条件,请不要使用服务。根据以下条款和条件,
You(Subscriber或You)访问服务:
1.访问服务

The Stack Exchange Network (the "Network") is a set of related Internet sites and other applications for questions and answers, owned and operated by Stack Exchange Inc. ("Stack Exchange"), a Delaware corporation. Please read these terms of service ("Agreement") carefully before using the Network or any services provided on the Network (collectively, "Services"). By using or accessing the Services, you agree to become bound by all the terms and conditions of this Agreement. If you do not agree to all the terms and conditions of this Agreement, do not use the Services. The Services are accessed by You ("Subscriber" or "You") under the following terms and conditions: 1. Access to the Services

根据本协议的条款和条件,Stack Exchange
可以提供服务,如
网络上更全面描述的,以及订阅者选择的服务,仅用于订阅者的
自用,不得用于任何第三方的使用或利益。服务
应包括但不限于Stack Exchange
为订户执行的任何服务,以及网络上任何内容的提供(如下面定义的
)。 Stack Exchange可以随时更改,暂停或
终止服务,包括
任何功能,数据库或内容的可用性。 Stack Exchange还可能对某些功能和服务施加
限制,或限制订户对部分或全部服务的
访问权限,恕不另行通知或承担责任。
Stack Exchange保留随时修改这些
服务条款的权利,通过在网络上发布修订后的服务条款并通过电子邮件提供通知,其中可能,或者在
网络上。订户应负责审核,并且b $ b熟悉任何此类修改。使用服务
订户在此类修改后构成订户的b $ b接受本协议的条款和条件经修改。

Subject to the terms and conditions of this Agreement, Stack Exchange may offer to provide the Services, as described more fully on the Network, and which are selected by Subscriber, solely for Subscriber’s own use, and not for the use or benefit of any third party. Services shall include, but not be limited to, any services Stack Exchange performs for Subscriber, as well as the offering of any Content (as defined below) on the Network. Stack Exchange may change, suspend or discontinue the Services at any time, including the availability of any feature, database, or Content. Stack Exchange may also impose limits on certain features and services or restrict Subscriber’s access to parts or all of the Services without notice or liability. Stack Exchange reserves the right, at its discretion, to modify these Terms of Service at any time by posting revised Terms of Service on the Network and by providing notice via e-mail, where possible, or on the Network. Subscriber shall be responsible for reviewing and becoming familiar with any such modifications. Use of the Services by Subscriber following such modification constitutes Subscriber's acceptance of the terms and conditions of this Agreement as modified.

如何通过换行符从该文本制作数组?

How can i make in array from that text by newlines?

我需要在每行的开头粘贴simbols>,如何做到这一点?

I need to paste in the begining of each line simbols "> ", how to do that?

推荐答案

使用 split()

前例

str = "abc\ndef";
console.log(str.split("\n"));

将打印出来

["abc", "def"] 

这篇关于如何通过JavaScript中的换行符从字符串创建数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆