Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Pattern Matcher reads white space wrong

$
0
0
As my project is beginning to take shape, most of the problems I've encountered, I've been able to solve, but this latest one cunningly beats me, not because of any complexities but because I don't know whats going on under the hood of the parser. I am using a pattern matcher() Pattern.compile("\\d+"); - (in JAVA) - to extract and read floats, but there were problems as white spaces are being interpreted as 0.0 808.00.0472.00.036.00.0202.00.018.00.024.00.0 782.00.096.00.036.00.0202.00.018.00.024.00.0 909.00.01028.00.036.00.0202.00.018.00.024.00.0 931.00.01149.00.036.00.0202.00.018.00.024.00.0 but should, correctly, be something like this 808.0 472.0 36.0 202.0 18.0 24.0 782.0 96.0 36.0 202.0 18.0 24.0 909.0 1028.0 36.0 202.0 18.0 24.0 931.0 1149.0 36.0 202.0 18.0 24.0 It was wrong because it was making white space to be 0.0 As said It was wrong because it was making white space to be 0.0 My quick fix was to use an if statement that exclude 0.0. Well I got away with it until the inevitable began to happen,- some of the real data started turning out to be 0.0, so my if statement was excluding the real data from being read. Any help on how to get this fixed? I need white space to be read as white space not as 0.0 public void readDataFromSelectedTextFile( File fPathplusName ){ List<Float> numbers = new LinkedList<Float>(); try { bufferedReader = new BufferedReader(new FileReader(fPathplusName)); while ((stringObjectData = bufferedReader.readLine()) != null){ Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(stringObjectData); while (m.find()) { numbers.add(Float.parseFloat(m.group())); } } ListIterator<Float> floatIterator = numbers.listIterator(); int i=0, t=7, n=0; float s, size=0; while( floatIterator.hasNext() ){ if( (s = floatIterator.next()) > 0 ){ ... ... plenty of good coding here ... ... } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }/**/ }

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>