Java halp
Go to solution
Solved by Nuluvius,
Your attempt is overcomplicated. Here is a more concise solution... I'm sure you can extend it to work with an array of start and end strings and whatever other guff you need (we won't do all the work for you after all):
import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Main{ public static void main(String[] args) { for(String s : decode("AAAAAATGAAAAAAAAAAAATGAAATGAAATGAA", "ATG", "TGA")) { System.out.println(s); } } private static ArrayList<String> decode(String input, String start, String end) { ArrayList<String> result = new ArrayList<String>(); Pattern p = Pattern.compile(Pattern.quote(start) + "(.*?)" + Pattern.quote(end)); Matcher matcher = p.matcher(input); while (matcher.find()) { result.add(matcher.group(0)); } return result; }}
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now