String code processing

// Remove the extra 0 after the decimal point
public static String subZeroAndDot (String s) {
if (s.indexOf (".")> 0) {
s = s.replaceAll ("0+? " , " " ) ; / / go with Drop many I of 0 s = s . r e p l a c e A l l ( " [ . ] & quot ;, & quot; & quot;); // Remove the extra 0 s = s.replaceAll (& quot; [.] ", "");// The last one is then removed.
}
return S;
}
// string removing spaces
public void delSpacebar () {
String a = "fdi34 09df jk";
// a = a.replace ("", ""); // replace conversion parameter is a string; replaceAll conversion parameter is a regular expression
a = a.trim (); // Delete the spaces at the
beginning andend of the stringSystem.out.println (a);
}

// Turn the middle four digits of the phone number to ****
public static String switchPhone (String phone) {
if (phone.length () == 11) {
if (Pattern.compile ("[0-9] ") .matcher (phone) .matches ()) {
phone = phone.substring (0, 3) + phone.substring (3) .replaceAll ("^ \ d {4}", "
***");
} else {
phone = "There is a non-digit";
}
} else {
phone = "The length is wrong";
}
return phone;
}

// The first letter capitalized
public String upperCase (String str) {
return str.substring (0, 1) .toUpperCase () + str.substring (1);
}

@Test
// Time processing
public void date () {
try {
Long timeStamp = System.currentTimeMillis (); // Get current timestamp
System.out.println (timeStamp);
Date nowDate = new Date (); // Current time
System.out.println (nowDate);
// DateFormat df = new SimpleDateFormat (“yyyy-MM-dd E a HH: mm: ss”);
SimpleDateFormat sdf = new SimpleDateFormat (“yyyy-MM-dd HH: mm: ss ”); // SimpleDateFormat is a DateFormat subclass, usually SimpleDateFormat
String dateStr = sdf.format (nowDate); // Time format is converted to string format
System.out.println (dateStr);
Date date = sdf.parse (dateStr ); // String format is converted to time format
System.out.println (date);
} catch (ParseException e) {
e.printStackTrace ();
}
}

Published 18 original articles · Like1 · Visits 1417

Guess you like

Origin blog.csdn.net/qiteng_sijia/article/details/86089453