Java/Apache Common/String Utils
Содержание
Get difference between two strings
<source lang="java">
/* 4
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.getLevenshteinDistance("govern", "government")); }
}
</source>
String abbreviate
<source lang="java">
/* Take ti...
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.abbreviate("Take time off working", 0, 10)); }
}
</source>
String capitalize
<source lang="java">
/* VanderLust
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.capitalize("vanderLust")); }
}
</source>
String center
<source lang="java">
/*
MTV
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.center("MTV", 7, "=")); }
}
</source>
String chop
<source lang="java">
/* Dan
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.chop("Dane")); }
}
</source>
String chop by
<source lang="java">
/* temperat
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.chomp("temperature", "ure")); }
}
</source>
String contains
<source lang="java">
/* true
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.contains("Dorothy", "oro")); }
}
</source>
String contains none
<source lang="java">
/* false
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.containsNone("r u m t", new char[] {"r", "o"})); }
}
</source>
String contains only
<source lang="java">
/* false
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.containsOnly("r u m t", new char[] {"r", "o"})); }
}
</source>
String count matches
<source lang="java">
/* 2
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.countMatches("arthur", "r")); }
}
</source>
String delete white space
<source lang="java">
/* ffff
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.deleteWhitespace("f f f f")); }
}
</source>
String difference
<source lang="java">
/* ment
*/
import org.apache.rumons.lang.StringUtils; public class StringUtilsExampleV1 {
public static void main(String args[]) { System.err.println(StringUtils.difference("govern", "government")); }
}
</source>
String Escape Utils
<source lang="java">
/* Are you for real? What\"s in a name? Mc""Williams <data> <data>
- /
import org.apache.rumons.lang.StringEscapeUtils; public class StringUtilsEscapeExampleV1 {
public static void main(String args[]) { String unescapedJava = "Are you for real?"; System.err.println( StringEscapeUtils.escapeJava(unescapedJava)); String unescapedJavaScript = "What"s in a name?"; System.err.println( StringEscapeUtils.escapeJavaScript(unescapedJavaScript)); String unescapedSql = "Mc"Williams"; System.err.println( StringEscapeUtils.escapeSql(unescapedSql)); String unescapedXML = ""; System.err.println( StringEscapeUtils.escapeXml(unescapedXML)); String unescapedHTML = "<data>"; System.err.println( StringEscapeUtils.escapeHtml(unescapedHTML)); }
}
</source>