猿问

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

我正在尝试在 word 文档中的每个单词后添加引号和逗号。


For example:


apple

banana

carrot


Goes into:


"apple",

"banana",

"carrot",

我应该在 find 部分和 replace 部分中输入什么来达到这个结果?


慕少森
浏览 280回答 2
2回答

杨魅力

LibreOffice Writer您可以按打开CTRL + H查找和替换工具。您必须启用正则表达式并进行如下配置:寻找:(\w+)代替:"$1"然后按全部替换。我相信你也可以在 ms-word 上做到这一点。

慕码人8056858

不确定为什么您的问题中同时包含 JavaScript 和 Java 标签,但我会假设您的意思是 Java。您想要使用 Java 执行的操作的可能解决方案:1)让我们首先读入带有单词的文件并创建一种写出结果的方法:String contents = new String(Files.readAllBytes(Paths.get("path-to-input"))); // inputBufferedWriter writer = new BufferedWriter(new FileWriter("path-to-output")); // output2)我们已经将文件的内容作为单个字符串读取,现在让我们将其拆分为单个单词。我们将通过回车符和换行符拆分来做到这一点(取决于您的文件,只有换行符可能就足够了):String[] splitContents = contents.split("\r\n");3) 让我们将上面数组中的字符串更改为我们希望在文件中看到的字符串。然后将它们输出到文件:&nbsp; &nbsp; for(int i = 0; i < splitContents.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; splitContents[i] = "\"" + splitContents[i] + "\","; //create new string&nbsp; &nbsp; &nbsp; &nbsp; writer.write(splitContents[i]); //write new string to file&nbsp; &nbsp; &nbsp; &nbsp; writer.newLine(); //append newline&nbsp; &nbsp; }4 )不要忘记flush()和close():writerwriter.flush();writer.close();
随时随地看视频慕课网APP

相关分类

Java
我要回答