Inferred string strings are numbers, JSON structures, XML structures

Source: Internet
Author: User

Import org.json.JSONException; Import Org.json.JSONObject; Import org.dom4j.DocumentException; Import Org.dom4j.DocumentHelper; public class Stringtest {/** * @param args */public static void main (string[] args) {String string1 = "123"; String string2 = "fdgsewe323"; String String3 = "{/" task/":/" 324vfsdfg/"}"; String String4 = "<ww>3243</ww>"; System.out.println ("String1::number" +isnumber (string1)); System.out.println ("String2::number" +isnumber (string2)); System.out.println ("String3::json" +isjson (string3)); System.out.println ("String4::xml" +isxml (String4)); System.out.println ("String1::json" +isjson (string1)); System.out.println ("String2::xml" +isxml (string2)); System.out.println ("String3::number" +isnumber (string3)); System.out.println ("String4::xml" +isxml (String4)); System.out.println ("String1::" +gettype (string1)); System.out.println ("string2::" +gettype (string2)); System.out.println ("String3::" +gettype (String3)); System.out.println ("String4::" +gettype (strING4)); The public static String GetType (string string) {if (Isnumber (string)) return "number"; else if (Isjson (string)) return "Js On "; else if (Isxml (string)) return "XML"; else return "String"; }/** * Infers if the string is a number */public static Boolean Isnumber (string value) {return Isinteger (value) | | isdouble (value);}/** * push Whether the broken string is an integer */public static boolean Isinteger (String value) {try {integer.parseint (value); return true;} catch (Numberfo Rmatexception e) {return false;}} /** * Infers whether the string is a floating-point number */public static Boolean isdouble (string value) {try {double.parsedouble (value), if (Value.contains (". ")) return true; return false; } catch (NumberFormatException e) {return false;}}  /** * Inferred if it is a JSON structure */public static Boolean Isjson (String value) {try {new Jsonobject (value)} catch (Jsonexception e) { return false; } return true; }/** * Inferred whether it is an XML structure */public static Boolean Isxml (String value) {try {documenthelper.parsetext (value);} catch (Document Exception e) {return false;} return true; } }  

Inferred string strings are numbers, JSON structures, XML structures

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.