简体   繁体   English

如何在ms单词列表中的每个单词之后添加引号,逗号和空格?

[英]How do I add quotes, commas, and spaces after each word in a ms-word list?

I am trying to add quotes and a comma after each word in a word document. 我正在尝试在Word文档中的每个单词后添加引号和逗号。

For example:

apple
banana
carrot

Goes into:

"apple",
"banana",
"carrot",

What should I put in the find section and replace section to arrive at this outcome? 我应该在查找部分和替换部分中添加什么才能达到此结果?

On LibreOffice Writer you can press CTRL + H to open the find and replace tool. LibreOffice Writer您可以按CTRL + H打开查找和替换工具。

You must enable regular expression and configure as following: 您必须启用正则表达式并进行以下配置:

Find: (\\w+) 查找: (\\w+)

Replace: "$1" 替换: "$1"

And then press replace all. 然后按全部替换。

I am sure you can do it on ms-word as well. 我相信您也可以在ms-word上执行此操作。

LibreOffice作家

Not sure why you have both JavaScript and Java tags in your question, but I will assume you meant Java. 不知道为什么要在问题中同时包含JavaScript和Java标记,但是我假设您的意思是Java。 A possible solution to what you want to do using Java: 使用Java可能要解决的问题的可能解决方案:

1) Lets first read in the file with the words and create a way to write out the result: 1)首先用单词读入文件,然后创建一种写出结果的方法:

String contents = new String(Files.readAllBytes(Paths.get("path-to-input"))); // input
BufferedWriter writer = new BufferedWriter(new FileWriter("path-to-output")); // output

2) We've read the contents of the file as a single String, lets split it now into individual words. 2)我们已经将文件的内容作为单个String读取,现在将其拆分为单个单词。 We will do this by splitting by carriage return and newline (depending on your file, only newline may be sufficient): 我们将通过回车符和换行符进行拆分(取决于您的文件,仅换行符就足够了):

String[] splitContents = contents.split("\r\n");

3) Let's change the Strings in the array above to the ones that we want to see in our file. 3)让我们将上面数组中的字符串更改为我们想要在文件中看到的字符串。 Then output them to file: 然后将它们输出到文件:

    for(int i = 0; i < splitContents.length; i++) {
        splitContents[i] = "\"" + splitContents[i] + "\","; //create new string
        writer.write(splitContents[i]); //write new string to file
        writer.newLine(); //append newline
    }

4) And don't forget to flush() and close() the writer : 4)并且不要忘记flush()close() writer

writer.flush();
writer.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM