import java.util.regex.*;
public class BlankRemover
{
/* remove leading whitespace */
public static String ltrim(String source) {
return source.replaceAll("^\\s+&qu ot;, "");
}
/* remove trailing whitespace */
public static String rtrim(String source) {
return source.replaceAll("\\s+$&qu ot;, "");
}
/* replace multiple whitespaces between words with single blank */
public static String itrim(String source) {
return source.replaceAll("\\b\\s{2 ,}\\b", " ");
}
/* remove all superfluous whitespaces in source string */
public static String trim(String source) {
return itrim(ltrim(rtrim(source) ));
}
public static String lrtrim(String source){
return ltrim(rtrim(source));
}
public static void main(String[] args){
String oldStr =
"> <1-2-1-2-1-2-1-2-1-2-1> <";
String newStr = oldStr.replaceAll("-", " ");
System.out.println(newStr);
System.out.println(ltrim(newStr));
System.out.println(rtrim(newStr));
System.out.println(itrim(newStr));
System.out.println(lrtrim(newStr));
}
}
Thursday, November 15, 2007
[JAVA] Remove leading or trailing spaces in a String using regular expressions
Centos 7 reset root/ any user lost password / lockout due to cant remember password
1. Need to be in front of the terminal. (Physically if not vm). 2. Reboot the server 3. Press 'e' in the GRUB2 boot screen. 3. bunch...
-
S/N: KGR3T-F2C26-RRTGT-D6DQT-QBBB3
-
Original Source:: http://www.zytrax.com/tech/pc/serial.html Tech Info - USB and Firewire USB and FireWire (IEEE 1394a and b) represent the...