skip to Main Content

I have multiple lists (in a .txt file) which I’d like to quickly convert to an array. I’ve seen this question asked and answered here for Notepad++, but not for Xcode. Is it possible to similarly here?

AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
Beige
Bisque
Black
BlanchedAlmond

and convert it to an array literal…

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

//the highest rated answer for this on the notepad++ thread: Add quotation at the start and end of each line in Notepad++
enter image description here

I should add I can use the expression (.+) in the find function, but not the "1".

2

Answers


  1. Chosen as BEST ANSWER

    Looks like it's not possible to use Regular Expressions to replace in Xcode. I ended up using Atom text editor to get this done, and the following expressions:

    Find:

    (n+)
    

    Replace:

    ",rn"
    

  2. To add quotation marks to the start and end of every line with regular expressions in Xcode, choose the “Regular expression” search option and replace ^.*$ (i.e., ^ is the start of the line, .* is zero or more of any character, and $ is the end of the line) with "$0" (i.e., a quotation mark, followed by capture group number zero, followed by a final quotation mark):

    enter image description here


    You can also use multi-cursors. You can, for example, hold down the key and click-drag with your mouse, and then hit ◀︎ to go to the start of the lines, " for the opening quotation mark, ▶︎ to go to the end of the lines, and " for the closing quotation mark.

    enter image description here

    And while you can hold and and click-drag to make a bunch of multi-cursors, you can also toggle individual ones on and off with -clicks.


    If you want to remove the newline characters, too, with the regex approach, after doing the regex replacement, just go back to a normal “Contains” search and replace the “line break”, ⏎, with a comma and space:

    enter image description here

    Or, with the multi-cursor approach, after adding the quotation marks, go to the end of the line, add the comma and space, and hit the key to delete the line breaks:

    enter image description here

    You just need to delete the trailing comma at the very end.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search