apache-stringutils

Extract digits from string - StringUtils Java

限于喜欢 提交于 2019-12-28 03:51:07
问题 I have a String and I want to extract the (only) sequence of digits in the string. Example: helloThisIsA1234Sample. I want the 1234 It's a given that the sequence of digits will occur only once within the string but not in the same position. (for those who will ask, I have a server name and need to extract a specific number within it) I would like to use the StringUtils class from Apache commomns. Thanks! 回答1: Use this code numberOnly will contain your desired output. String str=

Add exclude apache.commons.lang3 from net.sourceforge.dynamicreports

半城伤御伤魂 提交于 2019-12-24 03:14:20
问题 I want to add a dependency in my project to use dynamic report, i found this: <dependency> <groupId>net.sourceforge.dynamicreports</groupId> <artifactId>dynamicreports-core</artifactId> <version>4.0.0</version> </dependency> but when i add it to my pom.xml , i got this error : The method isNoneBlank(String) is undefined for the type StringUtils error in StringUtils.isNoneBlank(...) . I think it's a conflit in versions of lang3 how can i add an exclude for commons.lang3 ? 回答1: That's how you

Concatenate string values with delimiter handling null and empty strings in java 8? [duplicate]

女生的网名这么多〃 提交于 2019-12-17 22:58:05
问题 This question already has answers here : Join comma if not empty or null (9 answers) Closed 3 years ago . In Java 8 I have some number of String values and I want to end up with a comma delimited list of valid values. If a String is null or empty I want to ignore it. I know this seems common and is a lot like this old question; however, that discussion does not address nulls AND spaces (I also don't like the accepted answer). I've looked at Java 8 StringJoiner, commons StringUtils (join) and

decode string encoded in utf-8 format in android

 ̄綄美尐妖づ 提交于 2019-12-17 10:59:30
问题 I have a string which comes via an xml , and it is text in German. The characters that are German specific are encoded via the UTF-8 format. Before display the string I need to decode it. I have tried the following: try { BufferedReader in = new BufferedReader( new InputStreamReader( new ByteArrayInputStream(nodevalue.getBytes()), "UTF8")); event.attributes.put("title", in.readLine()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch

StringUtils isNumeric returns true when input is “???”, why? [duplicate]

醉酒当歌 提交于 2019-12-09 17:51:44
问题 This question already has answers here : Why does Apache Commons consider '१२३' numeric? (5 answers) Closed 3 years ago . I was reading the commons.apache.org isNumeric method definition and it states: StringUtils.isNumeric("???") = true; I am not sure why "???" is considered to be numeric. My guesses are: A "?" is considered a unicode digit It is some kind of regex pattern 回答1: I was able to find the answer to this question by looking at the StringUtils source code for the isNumeric method.

Apache StringUtils vs Java implementation of replace()

我的未来我决定 提交于 2019-12-09 03:05:06
问题 What would be the difference between Java 1.4.2's implementation of replace, and Apache 2.3's implementation? Is there a performance gain one over another? Java 1.4.2 replace Apache 2.3 replace 回答1: The String.replace() method you linked to takes two char values, so it only ever replaces on character with another (possibly multiple times, 'though). The StringUtils.replace() method on the other hand takes String values as the search string and replacement, so it can replace longer substrings.

Apache StringUtils vs Java implementation of replace()

心已入冬 提交于 2019-12-01 03:19:06
What would be the difference between Java 1.4.2's implementation of replace, and Apache 2.3's implementation? Is there a performance gain one over another? Java 1.4.2 replace Apache 2.3 replace The String.replace() method you linked to takes two char values, so it only ever replaces on character with another (possibly multiple times, 'though). The StringUtils.replace() method on the other hand takes String values as the search string and replacement, so it can replace longer substrings. The comparable method in Java would be replaceAll() . replaceAll() is likely to be slower than the

Concatenate string values with delimiter handling null and empty strings in java 8? [duplicate]

夙愿已清 提交于 2019-11-30 04:44:10
This question already has an answer here: Join comma if not empty or null 8 answers In Java 8 I have some number of String values and I want to end up with a comma delimited list of valid values. If a String is null or empty I want to ignore it. I know this seems common and is a lot like this old question ; however, that discussion does not address nulls AND spaces (I also don't like the accepted answer). I've looked at Java 8 StringJoiner, commons StringUtils (join) and trusty guava (Joiner) but none seems like a full solution. The vision: where: val1="a", val2=null, val3="", val4="b" String

decode string encoded in utf-8 format in android

扶醉桌前 提交于 2019-11-27 14:06:19
I have a string which comes via an xml , and it is text in German. The characters that are German specific are encoded via the UTF-8 format. Before display the string I need to decode it. I have tried the following: try { BufferedReader in = new BufferedReader( new InputStreamReader( new ByteArrayInputStream(nodevalue.getBytes()), "UTF8")); event.attributes.put("title", in.readLine()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } I have also tried this: try

Extract digits from string - StringUtils Java

蹲街弑〆低调 提交于 2019-11-27 12:59:17
I have a String and I want to extract the (only) sequence of digits in the string. Example: helloThisIsA1234Sample. I want the 1234 It's a given that the sequence of digits will occur only once within the string but not in the same position. (for those who will ask, I have a server name and need to extract a specific number within it) I would like to use the StringUtils class from Apache commomns. Thanks! Use this code numberOnly will contain your desired output. String str="sdfvsdf68fsdfsf8999fsdf09"; String numberOnly= str.replaceAll("[^0-9]", ""); Michael Bavin I always like using Guava