How to use the Java-split () function and the trim () function

Source: Internet
Author: User

How to use the split () function and the trim () function


This address: http://blog.csdn.net/caroline_wendy/article/details/24465141


Detailed reference Java API: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html


The split () function is based on the parameters such as ",", "-", "", and so on, cutting string strings , returning an array of string (string[]), and being able to specify the elements by index.

If not found, the entire string string is returned as the No. 0 element of the string array (string[]).


The trim () function is a trailing space that removes string strings;


Code:

/** * @author Spike * @time 2014.4.25 */public class Split {public static void split () {String details = "M 2.9-9km W of Alberto Oviedo Mota, Mexico "; String magnitudestring = Details.split ("") [1]; System.out.println (magnitudestring);d etails = Details.split (",") [1].trim (); SYSTEM.OUT.PRINTLN (details);} public static void Main (string[] args) {//TODO auto-generated method Stubsplit ();}}

Output:

2.9Mexico




How to use the Java-split () function and the trim () function

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.