c# - Why do I get "Operator "==" cannot be applied to operands of type "char" and "string"" when if statement check whether word contains letter "e"? -


in program, want load text file containing words. go ahead , check though each word if contain letter "e". if so, replace letter "e" 3, otherwise don't change letter. then, proceed write new file modified words.

my problem that, in 'if' condition check, "operator "==" cannot applied operands of type "char" , "string"". think, maybe cannot perform operation '==' on char , substring number. so, how go remedying this. thank you!

public static void main (string[] args)     {         system.console.writeline ("please enter location of text file leet: ");          string myfirstfilepath = console.readline ();         string[] firstfile = system.io.file.readalllines (myfirstfilepath);          int wordcount = 0;         arraylist mixedlist = new arraylist();          system.console.writeline ("please enter location of new text file saved: ");         string newfiledestination = console.readline ();          textwriter writetonewfile = new streamwriter (newfiledestination);         foreach (string 1 in firstfile) {             string word;             (int = 0; <= one.length; i++) {                 if (one[i] == "e") {                     word = word + "3";                 } else {                     word = word + word.substring(i);                     writetonewfile.writeline (one);                     wordcount++;                 }             }         }         writetonewfile.close ();         console.writeline (wordcount);         console.writeline ("press key exit.");         system.console.readkey ();      } 

just replace one[i] == "e" one[i] == 'e'.

using double quote invoke string type, whereas using single quote invoke char type


furthermore, declare string word; , use (word = word + "3") without assign it. recommend assign avoid potential side effect : string word = "";


Comments