How to get array from string contained identical symbols in Ruby?
来源:互联网 发布:黄金价格数据下载 编辑:程序博客网 时间:2024/05/05 09:13
I have string like this: "1112222355". How can I get array like that ["111","2222","3","55"] using Ruby?
Assuming you want to group only consecutive elements, use Enumerable#chunk:
> "1112222355".chars.chunk { |x| x }.map { |c, cs| cs.join }=> ["111", "2222", "3", "55"]
"1112222355".scan(/((.)\2*)/).map(&:first)# => ["111", "2222", "3", "55"]
0 0
- How to get array from string contained identical symbols in Ruby?
- How to get array from string contained identical symbols in Ruby?
- How to get file extension from string in C++
- How to get byte array from imageview
- How to gsub \ in ruby array?
- How to create this array in Ruby?
- how to remove nil and blank string in an array in Ruby
- How to get rid of `deprecated conversion from string constant to 'char*'` warnings in GCC?
- How to format strings in an array in ruby?
- Ruby: how to sort array of string parsing the content
- How to add two multidimensional array in ruby
- String to array to multidimensional hash in ruby
- How to switch from POST to GET in PHP CURL
- How to convert char array to String in Java
- How to split a string to array in objective-c?
- How to create ArrayList (ArrayList from array (T[]) in Java
- How to convert from int to string in objective c
- How to convert from int to string in objective c
- 关于 “There is no Action mapped for namespace / and action name . - [unknown location]” 的解决方法
- 五种常见的电子商务模式:B2B、B2C、C2B、C2C、O2O
- iOS7 动画学习
- 用两个栈实现一个队列
- STL常用算法4----mem_fun
- How to get array from string contained identical symbols in Ruby?
- ios创建画笔的例子(双笔画效果)
- iOS 播放声音和震动
- C 语言与C++的区别于联系
- python中multiprocessing.pool函数介绍<转>
- Best Time to Buy and Sell Stock
- HDU 4814 Golden Radio Base
- android layoutanimation 实现listview /gradview 的动画效果
- 如何将Web工程部署在本地Tomcat的webapps目录下