+ 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)

26th Sep 2018, 12:20 PM
Rifat Bin Salam
Rifat Bin Salam - avatar
3 odpowiedzi
+ 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
26th Sep 2018, 2:06 PM
dhm
0
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#split-java.lang.String- Does this help?
26th Sep 2018, 12:49 PM
CodeMStr
CodeMStr - avatar
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
26th Sep 2018, 2:41 PM
CodeMStr
CodeMStr - avatar