Notepad++中每行的开头和结尾添加引号 [英] Add quotation at the start and end of each line in Notepad++

查看:48
本文介绍了Notepad++中每行的开头和结尾添加引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表(在 .txt 文件中),我想快速将其转换为 JavaScript 语法,因此我想采用以下内容:

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", ... ]

我在记事本++中有列表,我需要一个reg表达式来在行首添加 " 和在行尾添加 ", 并删除换行符...有没有人有一个快速的解决办法来做到这一点?我对正则表达式很糟糕.

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

推荐答案

一次更换将无法完成;您必须执行几个步骤.这是我的做法:

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. 查找(在正则表达式模式下):

  1. Find (in regular expression mode):

(.+)

替换为:

"\1"

这会添加引号:

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

  • 查找(在扩展模式下):

  • 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"
    

    手动添加 var myArray = 赋值和大括号:

    Add the var myArray = assignment and braces manually:

    var myArray = ["AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige", "Bisque", "Black", "BlanchedAlmond"];
    

  • 这篇关于Notepad++中每行的开头和结尾添加引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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