Results 1 to 2 of 2
- 11-24-2010, 08:34 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Regular Expressions and String.replaceAll()
Hello! This is my first post, so just trying to see how this turns out...
I am writing an NBT (Named Binary Tag) reader. I would like to remove all the double newlines. So:
Java Code:Hi Hi again
Java Code:Hi Hi again
IO.java
Java Code:import java.io.*; public class IO { public String strIn() { BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); String input = null; try { input = console.readLine(); } catch (IOException e) { input = "<" + e + ">"; } return input; } public double numIn() { BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); String input = null; try { input = console.readLine(); } catch (IOException e) { input = "<" + e + ">"; } return Double.parseDouble(input); } public void out(String ut) { System.out.println(ut); } public void out(int ut) { String go = Integer.toString(ut); out(go); } public void out(double ut) { String go = Double.toString(ut); out(go); } }
Java Code:import org.jnbt.*; import java.io.*; public class NBT { public static void main(String[] args) { // Terminal input IO io = new IO(); // Get Directory and Filename of file NBTInputStream in = null; System.out.println("Directory:"); String dir = io.strIn(); System.out.println("File:"); String file = io.strIn(); File f = new File(dir,file); // Get whole data try { in = new NBTInputStream(new FileInputStream(f)); } catch (IOException e) { System.out.println("Opps..."); System.exit(0); } Tag t = null; try { t = in.readTag(); } catch (IOException e) { System.out.println("ARG! "+e); System.exit(0); } String whole = t.toString(); // Excess stuff Removal whole = whole.replaceAll("[{]", ""); whole = whole.replaceAll("[}]", ""); whole = whole.replaceAll("[ ]", ""); whole = whole.replaceAll("entries", ""); whole = whole.replaceAll("oftype", ""); // Here is where I am stuck! whole = whole.replaceAll("$\n", "\n"); String[] line = null; // Split whole data into lines line = whole.split("\n"); // Print out whole data System.out.println(whole); int x = 0; // Split lines into definers and data String[][] data = new String[java.lang.reflect.Array.getLength(line)][]; while (x<java.lang.reflect.Array.getLength(line)) { data[x]=line[x].split("[:]"); x=x+1; } System.out.println(data[2][0]); System.out.println(data[2][1]); } }
- 11-25-2010, 12:41 AM #2
Similar Threads
-
Using regular expressions for search
By carderne in forum New To JavaReplies: 9Last Post: 05-24-2009, 05:58 AM -
Regular Expressions in java
By blue404 in forum Advanced JavaReplies: 2Last Post: 09-26-2008, 04:43 AM -
Using Quantifiers in regular expressions
By Java Tip in forum Java TipReplies: 0Last Post: 01-10-2008, 11:43 AM -
Regular expressions quantifiers
By Java Tip in forum Java TipReplies: 0Last Post: 12-25-2007, 12:18 PM -
regular expressions and string matching
By DennyLoi in forum New To JavaReplies: 1Last Post: 11-16-2007, 11:15 AM
Bookmarks