Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add quotation at the start and end of each line in Notepad++

I have a list (in a .txt file) which I'd like to quickly convert to JavaScript Syntax, so I want to take the following:

AliceBlue AntiqueWhite Aqua Aquamarine Azure Beige Bisque Black BlanchedAlmond 

and convert it to an array literal...

var myArray = ["AliceBlue", "AntiqueWhite", ... ] 

I have the list in notepad++ and I need a reg expression to add the " at the start of the line and ", at the end and remove the line break... does anyone have a quick fix to do this? I'm terrible with RegEx.

I often have to perform such tasks so to know how to do this would be a great benefit to me. Many thanks

like image 772
Mike Sav Avatar asked Jan 13 '12 10:01

Mike Sav


People also ask

How do you insert a double quote in a text file?

If we want to insert double quotes into a file we can do this by specifying Chr(34); the Chr function takes the ASCII value – 34 – and converts it to an actual character (in this case double quotes).


1 Answers

You won't be able to do it in a single replacement; you'll have to perform a few steps. Here's how I'd do it:

  1. Find (in regular expression mode):

    (.+) 

    Replace with:

    "\1" 

    This adds the quotes:

    "AliceBlue" "AntiqueWhite" "Aqua" "Aquamarine" "Azure" "Beige" "Bisque" "Black" "BlanchedAlmond" 
  2. Find (in extended mode):

    \r\n 

    Replace with (with a space after the comma, not shown):

    ,  

    This converts the lines into a comma-separated list:

    "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond" 

  3. Add the var myArray = assignment and braces manually:

    var myArray = ["AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond"]; 
like image 159
BoltClock Avatar answered Sep 30 '22 21:09

BoltClock