Last active
August 29, 2015 14:08
-
-
Save Echocage/212f299b77f19577cbd4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
public class parser { | |
public static Integer[] getId(String nameGoal) { | |
ArrayList<Integer> ids = new ArrayList<Integer>(); | |
try { | |
BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\John\\IdeaProjects\\Example\\src\\npcList.txt")); //Java doesn't like referencing local files so you need the full path | |
String readLine = ""; | |
do { | |
try { | |
readLine = in.readLine(); | |
if (readLine != null) { | |
if (readLine.contains(" - ")) { | |
String[] arr = readLine.split("-", 2); | |
String name = arr[1]; | |
if (name.trim().toLowerCase().equals(nameGoal.trim().toLowerCase())){ | |
int id = Integer.parseInt(arr[0].trim()); | |
ids.add(id); | |
} | |
} | |
} | |
} catch (IOException io) { | |
io.printStackTrace(); | |
} | |
} | |
while (readLine != null); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
Integer[] idArr = new Integer[ids.size()]; | |
return ids.toArray(idArr); | |
} | |
public static void main(String args[]) { | |
for(Integer i : getId("nex")) | |
System.out.println(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment