Created
March 12, 2017 13:36
-
-
Save peat-psuwit/429095070d899d443a4cf8a2535d1f61 to your computer and use it in GitHub Desktop.
Parse the string that starts with "A9" (include next 2 letters) and "B1" (include 2 last letters). F2-2016.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class ParseString { | |
public static ArrayList<String> parse(String input) { | |
ArrayList<String> result = new ArrayList<>(); | |
String[] splitInput = input.split(","); | |
for (int i = 0; i < splitInput.length; i++) { | |
String s = splitInput[i].trim(); | |
if (s.startsWith("A9")) | |
result.add(s.substring(2, 4)); | |
else if (s.startsWith("B1")) | |
result.add(s.substring(s.length() - 2)); | |
} | |
return result; | |
} | |
public static void main(String[] args) { | |
for (int i = 0; i < args.length; i++) { | |
System.out.println(parse(args[i])); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment