如何在数组中的单词中添加引号以将它们视为字符串

时间:2021-05-27 15:45:17

In excel, I have a list of city names in a single cell that are comma delimited like this:

在excel中,我在单个单元格中有一个城市名称列表,以逗号分隔,如下所示:

Melrose, Mott Haven, Port Morris, Hunts Point, Longwood, Claremont, Concourse Village,
Crotona Park, Morrisania, Concourse, High Bridge, Fordham, Morris Heights, Mount Hope,
etc.

What I want to do is use them as an array in Ruby. However, without quotations around each city name, Ruby will not treat each city name as a string and thinks they are method names. I don't know how to do a function in excel that iterates through each word (since they are all in the same cell) and adds quotes around them, so is there a way to do this in pure Ruby?

我想要做的是在Ruby中将它们用作数组。但是,如果没有围绕每个城市名称的引用,Ruby不会将每个城市名称视为字符串,并认为它们是方法名称。我不知道如何在excel中执行迭代每个单词的函数(因为它们都在同一个单元格中)并在它们周围添加引号,所以有没有办法在纯Ruby中执行此操作?

I want something like this:

我想要这样的东西:

"Melrose", "Mott Haven", etc....

Just to clarify: I have the data in excel with all the words separated by commas in a single cell and was just wondering about a way to use Ruby to interate through each word to add quotes around each word.

只是为了澄清:我在excel中有数据,所有单词都用逗号分隔在单个单元格中,只是想知道如何使用Ruby来交互每个单词以在每个单词周围添加引号。

1 个解决方案

#1


3  

"Melrose, Mott Haven, Port Morris, Hunts Point, Longwood".split(", ")

#1


3  

"Melrose, Mott Haven, Port Morris, Hunts Point, Longwood".split(", ")