java - Fail to use a substring to print out part of a sentence -
the basic algorithm have input file has number of sentences, each sentence on each line.i want print out part of sentence position s e code below, prints out blank lines.can show me mistakes is?
public class email13 { static boolean isvalidemailcharacter(char c) { boolean result = false; if((c>='a'&&c<='z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||(c=='.')||(c=='-')||(c=='+')) result = true; return result; } public static void main(string[] args) throws exception{ bufferedreader cin, fin; cin = new bufferedreader(new inputstreamreader(system.in)); //description system.out.println("programmer: minh nguyen"); system.out.println("description: program start final project."); system.out.println(); string namein, nameout, dein, deout; namein=""; nameout=""; dein = "filecontainingemails.txt"; system.out.print("enter input filename [default:" + dein + "]: "); namein = cin.readline(); if(namein.compareto("")==0){ namein = dein; deout = "copypastemyemails.txt"; system.out.print("enter output filename [default:" + deout + "]: "); nameout = cin.readline(); if(nameout.compareto("")==0) nameout = deout; } else if(namein.compareto("")>0){ deout = namein; system.out.print("enter output filename [default:" + deout + "]: "); nameout = cin.readline(); if(nameout.compareto("")==0) nameout = namein; } fin = new bufferedreader(new filereader(namein)); //read input file while(true) { if(!fin.ready()) break; string linefromfile; linefromfile = fin.readline(); int s, e, hasdot; (int = 0; < linefromfile.length(); i++) // each char in string... { if(linefromfile.charat(i)=='@') { for(s=i;s>-1;s--) { if(isvalidemailcharacter(linefromfile.charat(s))==false) break; } for(e=i; e< linefromfile.length(); e++) { if(isvalidemailcharacter(linefromfile.charat(e))==false) break; } string anemail = linefromfile.substring(s,e); system.out.println(anemail); } } } fin.close(); printwriter fout; fout = new printwriter(new filewriter(nameout)); fout.close(); } }
try doesn't work:( s=i; while(s>-1) { if(isvalidemailcharacter(linefromfile.charat(s))==false) break; else s = 0; s--; } e=i; while(e< linefromfile.length()) { if(isvalidemailcharacter(linefromfile.charat(e))==false) break; else e = linefromfile.length(); e++;`enter code here` }
Comments
Post a Comment