The split () function splits a string string, returns an array of string (string[]) based on parameters such as ",", "-", "", and so on, and can specify 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 to remove the trailing space of a string string;
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);
Details = Details.split (",") [1].trim ();
SYSTEM.OUT.PRINTLN (details);
public static void Main (string[] args) {
//TODO auto-generated method Stub
split ();
}
Output:
2.9
Mexico
Author: csdn Blog spike_king
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/