Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create array with empty string using %w[]

Tags:

syntax

ruby

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[]?

like image 320
tig Avatar asked Oct 19 '12 18:10

tig


People also ask

How do you create an empty string array?

For example, str = "" creates a string scalar that contains no characters. str = strings( n ) returns an n -by- n string array. Each element is a string with no characters.

How do I create an empty string array in typescript?

To declare an empty array for a type variable, set the array's type to Type[] , e.g. const arr: Animal[] = [] . Any elements you add to the array need to conform to the specific type, otherwise you would get an error. Copied!


1 Answers

A couple of options

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

%W[a b c] << " "

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

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

like image 130
professormeowingtons Avatar answered Oct 04 '22 16:10

professormeowingtons