i changed the import (4u) and i still get the highlights
regular expressions
Collapse
X
-
it fixed the prob
but it doesnt replace a double in a string is this pattern correct for a double "[0-9]{0,2}\\.{0,1}[0-9]{0,2}"; and it reads in every second line not every line i checked it with system.out
Code:private void write_to_file(String wplata_wyplata){ try{ BufferedReader in = new BufferedReader(new FileReader("konta//"+NumerKonta+".txt")); String wczytane_dane=""; String line = in.readLine(); double sd= sr_dost; Double a1 = new Double(sd); while((line = in.readLine()) != null) { wczytane_dane+=line; line = in.readLine(); wczytane_dane+='\n'; } String patternStr = "[0-9]{0,2}\\.{0,1}[0-9]{0,2}"; String replacementStr = a1.toString();; Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(wczytane_dane); String output = matcher.replaceFirst(replacementStr); System.out.println("output ze zmienionym balansem"+output); in.close(); //here will be writing to a file }catch (FileNotFoundException e) { System.err.println("Nie ma takiego konta(File not found!)"); }catch (IOException e) { System.err.println(e); } catch (NumberFormatException e) { System.out.println("NumberFormatException: " + e.getMessage()); }catch (Exception ex) { ex.printStackTrace(); } }Comment
-
You have two readlines - that's your 'every-other line' problemOriginally posted by oll3iit fixed the prob
but it doesnt replace a double in a string is this pattern correct for a double "[0-9]{0,2}\\.{0,1}[0-9]{0,2}"; and it reads in every second line not every line i checked it with system.out
Code:while((line = in.readLine()) != null) { wczytane_dane+=line; line = in.readLine(); }
As far as the regex goes - does the period need to be backwhacked?
I would think it would be something like [0-9]+.[0-9]+ just quick and rough, that's at least one 0-9, a period (not sure if this needs to be backwhacked or not), and at least one 0-9 digit, but could be any amount.
The way you have it, you pick up a number between 10 and 99 whose second digit is two or zero, and then three places after that. Is that what you want?Comment
Comment