45

I've got this:

var quoted_text = window.getSelection;

For example:

Accepting the Terms of Service

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

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?

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

user2484836
  • 461
  • 1
  • 4
  • 5

2 Answers2

78

Use split()

Fore example

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

will print out

["abc", "def"] 
Community
  • 1
  • 1
Akusete
  • 10,704
  • 7
  • 57
  • 73
17

Use JavaScript .split() function to create an array with elements split by '\n' and then manually iterate through that array and add '<' for each item. The following code may help :

var str="How\nare\nyou\ndoing\ntoday?";
var n = str.split("\n");
for(var x in n){   
    n[x]= '>'+n[x]; 
    alert(n[x]);
}
codeVerine
  • 742
  • 3
  • 14