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
Proxmox installation display out of range
Reference: https://forum.proxmox.com/threads/proxmox-ve-screen-out-of-range.131297/
-
How to remove BBCODE from a string ? <?php $String = "[b][color=#0000ff]TEST[/color][/b]"; $regex = '|[[\/\!]*?[^\[\]...
-
Original Source:: http://www.zytrax.com/tech/pc/serial.html Tech Info - USB and Firewire USB and FireWire (IEEE 1394a and b) represent the...