scanning patterns

Hello,

trying to figure out scanner patterns...actually, reading text file with information and would like to store string which is between triangle brackets <Hello> into a veriable.

code i have so far

import java.util.*;

import java.io.File;

import java.io.FileNotFoundException;

public class DataScanner {

private static void readFile(String fileName) {

try {

Scanner scanner =

new Scanner(new File(fileName));

scanner.useDelimiter

(System.getProperty("line.separator"));

while (scanner.hasNext()) {

parseLine(scanner.next());

}

}

catch (FileNotFoundException e) {

e.printStackTrace();

}

}

private static void parseLine(String line) {

Vector myStations = new Vector(); // collection of stations

Scanner lineScanner = new Scanner(line);

lineScanner.useDelimiter("\\s*,\\s*");

Scanner test = new Scanner(line);

test.findInLine(?);// trying to identify string between <> brackets

String stationname = lineScanner.next();

String linename = test.next();

int x = lineScanner.nextInt();

int y = lineScanner.nextInt();

myStations.add(new Station(x, y, stationname, linename));

System.out.println(myStations);

}

public static void main(String[] args) {

readFile("other.data");

}

}

Cheers, Stereocilia II

[1449 byte] By [stereociliaIIa] at [2007-10-3 9:28:20]
# 1
What are you having problems with?
CaptainMorgan08a at 2007-7-15 4:42:43 > top of Java-index,Java Essentials,Java Programming...
# 2
how to use patterns to identify particular string!....test.findInLine(?);// in this line i would like to scan for string that is between <>!...Cheers!
stereociliaIIa at 2007-7-15 4:42:43 > top of Java-index,Java Essentials,Java Programming...
# 3
int firstIndex = line.indexOf("<");int secondIndex = line.indexOf(">");String s = line.substring(firstIndex+1, secondIndex);Like that?
CaptainMorgan08a at 2007-7-15 4:42:43 > top of Java-index,Java Essentials,Java Programming...
# 4
looks interesting, but line String s = line.substring(firstIndex+1, secondIndex);doesnt compile?
stereociliaIIa at 2007-7-15 4:42:44 > top of Java-index,Java Essentials,Java Programming...
# 5

maybe will this help...

private static void parseLine(String line) {

Vector myStations = new Vector(); // collection of stations

Scanner lineScanner = new Scanner(line);

lineScanner.useDelimiter("\\s*,\\s*");

String stationname = lineScanner.next();

//String linename = lineScanner.findInLine(",");

int firstIndex = line.indexOf("<");

int secondIndex = line.indexOf(">");

String linename = line.substring(firstIndex, secondIndex);

int x = lineScanner.nextInt();

int y = lineScanner.nextInt();

myStations.add(new Station(x, y, stationname, linename));

System.out.println(myStations);

}

stereociliaIIa at 2007-7-15 4:42:44 > top of Java-index,Java Essentials,Java Programming...
# 6
ok...i have figured out why it is not working...text file has also other characters and it would not start scanning thru the lines unless the first lines starts with < and it will stop scanning as well last line with > cheers
stereociliaIIa at 2007-7-15 4:42:44 > top of Java-index,Java Essentials,Java Programming...
# 7

Hello, i hope you are still reading this topic...i am using this ( " \\s* [,)] \\ s * " ) pattern inside the code above to analyze each line. Input line is (Acton_Central, Kensal_Rise, National_Rail_Line). Works well, it assign me each string to a veriable, but the problem is when I am trying to lose this first ( bracket in the beginning of the line, like to change pattern to ( " \\s* [ ( , ) ] \\ s * " ) it is not in order anymore. Somehow one line is added.

help will be extremly appreciated!

cheers!

stereociliaIIa at 2007-7-15 4:42:44 > top of Java-index,Java Essentials,Java Programming...