使用 %w[] 创建空字符串数组 [英] Create array with empty string using %w[]

查看:33
本文介绍了使用 %w[] 创建空字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个空字符串数组['a', '', 'b', '', 'c'](不是一个空格字符串' '),使用 %W 我可以使用 %W[a #{} b #{} c],也可以连接数组,但是否可以创建数组空字符串只使用 %w[]?

To create an array with empty strings ['a', '', 'b', '', 'c'] (not one space strings ' '), using %W I can use %W[a #{} b #{} c], also I can concatenate arrays, but is it possible to create array with empty strings using just %w[]?

推荐答案

几个选项

%W[a b c #{''} z]

<代码>%W[a b c] <<<" "

(我知道这不是使用 %w{} 语法,而是为了更好的衡量:

(I know this isn't using the %w{} syntax, but for good measure:

'a,b,c,,z'.split(',')

这篇关于使用 %w[] 创建空字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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