I want to split strings in the form of EADGBE or DADF#AD into separate strings, each containing either one letter or one letter plus a # sign. Is there any more elegant way than iterating through the string with a brute-force sort of approach?
String.split obviously relies on delimiters, which are then discarded, which is not much use to me at all – for a couple of minutes there I thought split("[a-gA-G]#?"); was going to work, but no, that doesn’t help at all – I almost want the opposite of that…
Brute force is likely to be your best option, both in terms of code and performance.
Alternatively, you could use a
Matcher