Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Mihkel Kass
Greenhorn
+ Follow
news
2
Posts
1
Threads
since Mar 09, 2017
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads
Recent posts by Mihkel Kass
How to compare and change similar strings from txt file?
Tapas Chand wrote:
Welcome to the ranch
Post here what you have got so far.
Thank you!
Code:
package email; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class email { public static void main(String[] args) { BufferedReader br = null; try { br = new BufferedReader(new FileReader( "C:\\Users\\Rex\\workspace\\email\\src\\email\\userstry.txt")); String line; while ((line = br.readLine()) != null) { System.out.println(getEmail(line)); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) { br.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } public static String getEmail(String line) { String name = ""; String lastName = ""; boolean nameDone = false; char tab = '\t'; char space = ' '; for (char ch: line.toCharArray()) { if(nameDone == false) { if(ch != space && ch != tab) { name = name + ch; } else { if(!name.isEmpty()) { nameDone = true; } } } else { if(ch != space && ch != tab) { lastName = lastName + ch; } } } return name.toLowerCase().replace('ä', 'a').replace('ž','z').replace('ä','a') .replace('ö', 'o').replace('õ','o').replace('š','s').replace('ü','u') + "." + lastName.toLowerCase().replace('ä', 'a').replace('ž','z').replace('ä','a') .replace('ö', 'o').replace('õ','o').replace('ü','u').replace('š','s') + "@tthk.ee"; } }
Example from text file:
Tõnis Meel
Henri Külg
Anna Tõnisson
Tom Niit
Tom Niit
show more
8 years ago
Beginning Java
How to compare and change similar strings from txt file?
Hello!
How can I change similar strings taken from a txt file? For example:
"thisissame"
"thisissame"
Will become
"thisissame"
"thisissame2"
show more
8 years ago
Beginning Java