+ 1
Detecting String/integer next to any character?(java)
I want a way to detect some strings / integers next to a specific character. for example 34+56-90 I want my code to detect the 56 as it id next to + sign. Also it would be helpful if I can detect previous integer also. (java)
3 Réponses
+ 1
Like Niek said, the split function using a regular expression seems appropriate for your problem : it will split a given string based on the regular expression you specify.
Regular expressions are a very useful and powerful tool. Basically, it is a string that defines a set of rules for use with other strings (when searching, splitting, deleting etc.)
This topic deals with a very similar problem to yours :
https://stackoverflow.com/questions/9856916/java-string-split-regex
0
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#split-java.lang.String-
Does this help?
0
Also, keep in mind strings can be used as char arrays. This means that this: somestring[0] is valid and will return the first character in the string