Split string Ruby on Rails based on number of characters -


मैं इन नंबरों को विभाजित करना चाहता हूं

  a = 900000 b = 1800000 c = 5000 <  

एक [0] = 900

एक [1] = 000

ख [/ code>

इन में

एक [ 0] = 1800

b [1] = 000

c [0] = 5

सी [1] = 000

मैं यह कैसे कर सकता हूं?

श्रेणी के साथ प्रयोग:

  a = 1800000 [a.to_s [0 ... -3], ए.टी.ओ.एस [-3 ..-1]] # = & gt; ["1800", "000"]  

का उपयोग करना

  a.divmod (1000) # = & gt; [1800, 0] ए.डि_मॉड (1000) .मैप {| n | | '% 03d'% n} # = & gt; ["1800", "000"]  

नियमित अभिव्यक्ति का उपयोग करना:

  a.to_s.match (/ (। *) (। {3} ) $ /)। कब्जा # = & gt; ["1800", "000"]  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

c# - Create dynamic LINQ query expression at runtime which translates into a parameterized SQL query for nullable types -

cmake - cpack generates RPMs with %files entries that conflict with the RPM spec. How to fix? -