Common Methods in string

Source: Internet
Author: User

Common Methods in string

1. Public char charat (INT index)

Returns the index characters in the string.
2. Public int length ()
Returns the string length.
3. Public int indexof (string Str)
Returns the first position of STR in the string.

Public int lastindexof (string Str)

Returns the last position of STR in the string.

4. Public Boolean equals (string S ):

Compare whether the string and another are the same

Public Boolean inclusignorecase (string another)
Compare whether the string and another are the same (case-insensitive)

The equals () method compares the characters in a string object, and the = Operator compares whether two objects reference the same instance.
5. Public String Replace (char oldchar, char newchar)
Replace oldchar with newchar in the string

String Replace (charsequence original, charsequence replacement)

Replacement to replace original

6. Public Boolean startswith (string prefix)
Determines whether a string starts with a prefix.
7. Public Boolean endswith (string suffix)
Judge whether the string ends with suffix
8. Public String touppercase ()
Returns the string in uppercase.
9. Public String tolowercase ()
Returns the string in lowercase.
10. Public string substring (INT beginindex)
Returns the substring from beginindex to the end of the string.
11. Public string substring (INT beginindex, int endindex)
Returns the substring from beginindex to endindex.
13. Public String trim ()

Removes spaces at the beginning and end of a string.

14. Public int compareto (string S ):

If the current string is the same as S, 0 is returned; if it is greater than S, a positive value is returned; if it is less than S, a negative value is returned.

Public int comparetoignore (string S): case-insensitive comparison

15. Public Boolean regionmatches (INT firststart, string other, int otherstart, int length ):

Compares a specific region in a string with a specific region.

Public Boolean regionmatches (Boolean B, int firststart, string other, int otherstart, int length)

You can use parameter B to determine whether to ignore case sensitivity.

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.