Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can convert string into array?

# (this give me list eg : ,s, s, m ... list = list + "," + name 

i want using split and then join ...try to use below..i don't know what i am doing

list = list.split(',') + name + collect{|c| c.name}.to_sentence  list = list.split(',') + name + collect{|c| c.name}.Join(",") 

any ideas??

like image 717
user557657 Avatar asked Feb 02 '11 02:02

user557657


People also ask

Can we convert string to array in JavaScript?

The string in JavaScript can be converted into a character array by using the split() and Array. from() functions.

Can we convert a string to character array in java?

Java For Testers String str = "Tutorial"; Now, use the toCharArray() method to convert string to char array. char[] ch = str. toCharArray();

How do I convert a string to an array in Python?

To convert String to array in Python, use String. split() method. The String . split() method splits the String from the delimiter and returns the splitter elements as individual list items.


2 Answers

I noticed that this page comes up for generic google search of "string to char array ruby".

If you just want to convert string to char array in ruby,

"string".chars # ["s", "t", "r", "i", "n", "g"] 
like image 184
Jason Kim Avatar answered Sep 21 '22 12:09

Jason Kim


i don't understand your question, but if you want to convert string to array

>> "a string".split("") => ["a", " ", "s", "t", "r", "i", "n", "g"] 
like image 45
kurumi Avatar answered Sep 19 '22 12:09

kurumi