Continuation--Basic type--array __ Regular expressions

Source: Internet
Author: User

=~ in the String class, is an overloaded operator used to match a string on the left with a regular expression on the right, to return the location of the match or nil in the RegExp class, and the "=~" operator is to match the string on the right with the regular expression on the left.

Sub and Sub. To match a string with an expression

Gsun and Gsub. is one of the most important methods of a string class, and the difference between a sub method: A sub handles only the first matching object, while gsub iterates through the entire string, modifying each object to which it matches.

Array

Definition: The definition of a standard by using the symbol box to select a series of data separated by commas. For example: arr=[1,2,3,4] Constructs an array definition from a class method. There are mainly "[]" and "new" for example: arr=array[1,2,3,4] or arr=array.new general qualifier to generate an array: arr=%w (1 2 3 4 5) Other ways: arr= "1 2 3". Split ()

Common methods self& array: Array with, returns the intersection of two arrays self | Array: Arrays or, returns the set of two arrays Self + array: Array Plus, returns the concatenation self.length of two arrays: Returns the length of an array. Self.size: Ditto. Self.empty?: To determine whether an array is empty self.clear: Empty the array self<<obj: Append elements to the array itself, return itself Self<=>array: array comparison, returns -1,0,1 Self.push (obj ): Appends the object to the last element of the array and returns itself. Self.unshift (obj): Appends an object to the first element of the array and returns itself. Self.shift: Returns the first element of the array and deletes it, returns nil Self.uniq if the array is empty, deletes the duplicate item inside the array, and returns a new string self.uniq!; Deletes the duplicate item inside the array, returning nil or itself Self.delete (obj): Removes the element from the array, deletes all if the element has duplicates, and returns nil Self.concat (array) If there is no such element in the array: appends the element to the array, returns itself Self.reverse: Reverses the array, produces a new array, and returns self.reverse!: Reverses the array and returns its own self[n]: Returns an element of the nth element in the array, which goes beyond the border to return nil Self.join (sepstr=$): Joins the array element with the set delimiter, returning a string Self.sort: Sorts the array, returning the new string. self.sort!: Sort the array, returning to its own self.to_s: exporting the array as a string

Find and assign values

The lookup method includes "[]", "include?" Index "method and so on. []: Returns an element or substring in an array that has three prototypes. Self[int]->obj or nil, self[start,length]->subarray or Nil.self[range]->subarray or nil include?: To determine whether an object is in an array Index: Find the position of the object in the array

Assignment: The method of assigning values is mainly "[]=".

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.