java - Find String and replace it in the text document -
this question has answer here:
- replace + - 6 answers
i trying replace ? question marker - hyphen in text document being found not replaced
bad schwartau ? stockelsdorf ? zob/hbf. ? sandstr. ? universitätsklinikum ? grillenweg 9 haltestellen montag ? freitag bad schwartau/zob ... 04:21 04:54 05:40 06:03 06:18 06:33 06:48 07:03 07:21 07:33 08:03 11:03 code:
try { scanner = new scanner(file); int linenum = 0; while (scanner.hasnextline()) { string line = scanner.nextline(); linenum++; if(line.contains("?")) { line.replace("?", "-"); system.out.println("i found on line " + linenum); } } }
a java string immutable - means cannot changed, replaced.
try instead -
line = line.replace("?", "-");
Comments
Post a Comment