Common operations collation of the String class

Source: Internet
Author: User
Tags first string

A. String class character and string manipulation:

    • public char charAt (int index) finds the specified character according to the subscript

    • Public char[] ToCharArray () returns all string contents as a character array

    • public string (char[] value) converts all character arrays into string construction methods

    • public string (char[] Value,int offset,int count) changes the character array of the specified range into a string construction method


Two. String-like byte-action

    • Public Byte[]getbytes () turns a string into a byte array

    • public string (byte[]bytes) converts a byte array into a string construction method

    • public string (byte[]bytes,int offset,int length) converts the byte array of the specified range into a string construction method

    • Public srring (byte[]bytes,string charsetname) constructs a new String construction method by decoding the specified byte array with the specified charset


Three. The string class determines whether to start or end with the specified content

    • public boolean startsWith (String prefix) starts at the first position to determine whether to start with the specified content

    • public boolean startsWith (String prefix,int toffset) starts at the specified position to determine whether to start with the specified content

    • public boolean endsWith (String suffix) determines whether to end with the specified content


Four. Substitution of the String class:

    • Public String replace (char OldChar, char Newchar) replaces the specified character

    • public string replace (charsequence target,charsequence replacement) replaces the specified string

    • public string ReplaceAll (srring regex,string replacement) replaces the specified string regex represents a regular expression

    • public string Replacefirst (srring regex,string replacement) replaces the first string that satisfies a condition


Five. String interception operations for string classes

    • Public String substring (int beginindex) is truncated to the end starting at the specified position

    • public string substring (int beginindex,int endIndex) intercepts a string of a specified range note: Include the starting position but not the end position


Six. String splitting operation of String class

    • Public string[] Split (string regex) is split according to the specified string

    • Public string[] Split (string regex,int limit) splits the string and specifies the number of splits


Seven. String lookup operation for String class

    • Public Boolean contains (string s) returns whether a string exists

    • public int indexOf (int ch) finds from the beginning whether the specified character exists, char->int, if present, returns the position if no return-1 is present.

    • The public int indexOf (int ch,int fromIndex) finds the specified character from the specified location, char->int if it exists, returns the position if there is no return-1

    • public int indexOf (string str) finds from the beginning whether the specified string exists, returns a position if it exists, and returns 1 if it does not exist.

    • The public int indexOf (string str,int fromIndex) finds the specified string from the specified location, returns a position if it exists, and returns 1 if it does not exist.

    • Note: The above position is the first occurrence of the position

    • public int lastIndexOf (int ch) looks up from the last forward of the string, whether the specified character exists, returns the position if it exists, and returns 1 if it does not exist.

    • public int lastIndexOf (int ch,int fromIndex) looks forward from the specified end of the string, whether the specified character exists, returns a position if it exists, and returns 1 if it does not exist.


Eight. Other methods of operation of the String class

    • public Boolean isEmpty () determines whether it is empty, only the content is empty "".

    • public int Length () Gets the lengths of the strings

    • Public String tolowercase () turns lowercase

    • Public srring toUpperCase () to uppercase

    • Public String trim () removes the opening and closing spaces, and the space in the middle does not go

    • public string concat (string str) string connection operation


Common operations collation of the String class

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.