Please anybody to help to read string value in text file using C#

Discussion in 'Programming' started by Ravikumar, Mar 14, 2007.

  1. #1
    Hi,


    I have used C# in vs 2003, in my application i have to read text file, pick data from text file and insert into database, but the text file have some garbage value (garbage value "Ú" ) , so i should replcace this garbage value to single space, i tried to use stream reader to read text file, but the problem is stream reader not at all reading this garbage value, its awqlays neglecting this garbage value, the following code i have used in my application


    StreamReader reader = new StreamReader(@"d:\web_extract.txt");

    string str = reader.ReadToEnd();

    StringBuilder strbuild = new StringBuilder(str);

    string gb = "Ú";

    reader.Close();

    strbuild.Replace(gb," ");

    StreamWriter writer = new StreamWriter(@"d:\web_extract.txt");

    writer.Write(strbuild.ToString());

    writer.Close();


    please anybody help me to solve this problem and take me out, Advanced thanks for any reply.



    Thanks.
     
    Ravikumar, Mar 14, 2007 IP
  2. Froggie

    Froggie Well-Known Member

    Messages:
    665
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    120
    #2
    why dont you post the text file so we can help u debug it

    i would say that u need to pass the unicode to the constructor of the reader but send the file and we wills ee
     
    Froggie, Mar 15, 2007 IP