How to Make a Ruby Sub-Chain
source link: https://www.codesd.com/item/how-to-make-a-ruby-sub-chain.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Make a Ruby Sub-Chain
This question already has an answer here:
- Extract a substring from a string in Ruby using a regular expression 5 answers
I'm very new to ruby, in fact I just read it today. But I need to do something quick in Ruby, suppose I have a string ABC=180000. What I want to do is remove the last two chars and makes it become 8 chars of string, so the above case result should be 00001800
in case the string ABC=AA000, the final result is 00000AA0
Could you guys tell me how to do this quickly?
Thanks a lot!
Untested as send from mobile:
"180000"[0...-2].rjust 8,"0"
Have a look at the docs: http://ruby-doc.org/core-2.2.3/String.html
Related Articles
How to make this ruby code more readable?
How to make a javascript promise chaining more elegantly?
How to make a Ruby class as a chopped with Setter
I'm a little lost: how to make rails / ruby on a website?
Java: How to make a final sub-array?
How to make a function / sub-section available for all forms of a project?
How to make a ruby command line application with a pager?
How to make PHP faster: does chain creation cost?
Unable to understand how to make the ruby 'encryptor' base work
Part II: How to make Ruby AES-256-CBC and PHP MCRYPT_RIJNDAEL_128 play well together
How to make Maven find sibling modules, when mvn is running in the submodule directory?
How to make rails work with vue.js?
how to make a sub-submenu with css?
How to make Ruby structures?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK