Java string: classes or packages with advanced functions?
I am doing string manipulations and I need more advanced functions than the original ones provided in Java. For example, I'd like to return a substring between the (n-1)th and nth occurrence of a character in a string. My question is, are there classes already written by users which perform this function, and many others for string manipulations? Or should I dig on stackoverflow for each particular function I need?
Check out the Apache Commons class StringUtils, it has plenty of interesting ways to work with Strings. http://commons.apache.org/lang/api-2.3/index.html?org/apache/commons/lang/StringUtils.html
Have you looked at the regular expression API? That's usually your best bet for doing complex things with strings: http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html Along the lines of what you're looking to do, you can traverse the string against a pattern (in your case a single character) and match everything in the string up to but not including the next instance of the character as what is called a capture group. It's been a while since I've written a regex, but if you were looking for the character A for instance, then I think you could use the regex A([^A]*) and keep matching that string. The stuff in the parenthesis is a capturing group, which I reference below. To match it, you'd use the matcher method on pattern: http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#matcher%28java.lang.CharSequence%29 On the Matcher instance, you'd make sure that matches is true, and then keep calling find() and group(1) as needed, where group(1) would get you what is in between the parentheses. You could use a counter in your looping to make sure you get the n-1 instance of the letter. Lastly, Pattern provides flags you can pass in to indicate things like case insensitivity, which you may need. If I've made some mistakes here, then someone please correct me. Like I said, I don't write regexes every day, so I'm sure I'm a little bit off.
SerializedSystemIni.class in Jdev11g : Exception in thread “main” java.lang.NoClassDefFoundError: weblogic/security/internal/SerializedSystemIni
2D array - specify amount to new 2d array
Java Runnable jar with imageview doesn't show GUI
Wrapping text in a JavaFX TableView editable TextFieldTableCell
Error:(1531, 21) No resource found that matches the given name: attr 'cropImageStyle'
Managing consistent versions across multiple Maven projects
java.lang.OutOfMemoryError - How do I fix this? [duplicate]
AsyncHttpClient - Disable any authentication handling
Java 8 avoiding lots of if/else statements
switch off broadcast reciever
How to add event in calendarview in android studio
How to disable optimistic locking in Spring Data JPA
How can I convert a String into ArrayList by counting occurrence of each characters?
Ionic app development in Android Studio, Core Java
using an api key for google+ to make request from a desktop application in java
AplhaNumeric String sum calculation in java