ruby-Numbers & Strings

Source: Internet
Author: User

=begin         #字符串          #数字, Several classes of numbers:   fixnum: The largest integer value that the native machine byte can store, and  bignum: An integer value that exceeds the maximum integer value that can be stored by the native machine byte;   float: Stores floating-point types;  bigdecimal: Provides a floating-point number type of arbitrary precision;  numeric: All numbers of sub-classes, all other numeric types =end# strings of some basic methods p  "string"               #输出结果为: "String" p  "string"   * 2         #输出结果为: "stringstring" p  "String"  +  "Class"    #输出结果为: "Stringclass" "a". ord           # Gets the ASCII encoding of the first character of the string: "A"  <  "B"          # Compare the size of ASCII on both sides: true "WA"  =~ /a/        #用正则匹配字符在字符串中的位置, starting bit 0:1# Some basic methods of number types 5.times { |x| puts x }           #使用   Number of times method, output from 0 to 4 a large five number: 0\n1\n2\n3\n4\n5.times { puts  "a"  }            #使用   times .times  method, will "a" continuous output five times: A\na\na\na\na\n5.upto (Ten)  { |x| puts x   }      #使用   Start value. Upto (end value)   method for controlling the output range: 5\n6\n7\n8\n9\n10\n10.downto (5)  { |x| puts x }     #使用   End value. Downto (initial value)   Reverse output: 10\n9\n8\n7 \n6\n5\n15.step (50, 8)  { |x| puts x }   #使用   initial value. Step (end value,  stepping value) )   output result, result less than equals end value: 15\n23\n31\n39\n47\n#bigdecimal usage require  ' BigDecimal ' a = bigdecimal.new ( "0.07") p  (a * 100). to_i


This article is from the "Invite the Wind" blog, please be sure to keep this source http://yaoyuechengfeng.blog.51cto.com/2958475/1729115

ruby-Numbers & Strings

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.