2010-06-09 5 views
0

웹 사이트에서 히브리어로 문자열을 찾으려고합니다. 독서 코드가 첨부되어 있습니다.C가 아닌 영어 HTML 페이지 읽기 #

이후에는 streamReader를 사용하여 파일을 읽으려고 시도하지만 다른 언어의 문자열과 일치시킬 수 없습니다. 내가 어떻게해야할까요?

// used on each read operation 
    byte[] buf = new byte[8192]; 

    // prepare the web page we will be asking for 
    HttpWebRequest request = (HttpWebRequest) 
     WebRequest.Create("http://www.webPage.co.il"); 

    // execute the request 
    HttpWebResponse response = (HttpWebResponse) 
     request.GetResponse(); 

    // we will read data via the response stream 
    Stream resStream = response.GetResponseStream(); 

    string tempString = null; 
    int count = 0; 
    FileStream fileDump = new FileStream(@"c:\dump.txt", FileMode.Create); 
    do 
    { 
     count = resStream.Read(buf, 0, buf.Length); 
     fileDump.Write(buf, 0, buf.Length); 

    } 
    while (count > 0); // any more data to read? 

    fileDump.Close(); 

답변

0

당신은 적절한 인코더 누락, 세부 사항

에 대한 WebResponse.GetResponseStream Method에서 살펴 업데이트 : 사용 히브리어 (윈도우) 인코딩이

Encoding encode = System.Text.Encoding.GetEncoding(1255); // Hebrew (Windows) 

// Pipe the stream to a higher level stream reader with the required encoding format. 
StreamReader readStream = new StreamReader(resStream , encode); 
+0

아무것도 ...을 생각 내 문제는 문자열을 검색하는 것과 관련이 있습니다. 일치 할 수는 없습니다. str.contains ("other language code"); 맞습니까? 내가 어떻게해야할까요? – AYBABTU

+0

검색된 메시지를 인코딩하려고했으나 실패했습니다. string messageToFind = "otherLanguage"; UTF8Encoding utf8 = 새 UTF8Encoding(); Byte [] encodedBytes = utf8.GetBytes (messageToFind); messageToFind = encodedBytes.ToString(); – AYBABTU

0

1255 그것을 해결된다. 문제는 잘못된 인코딩을 선택했다

, 나는 UTF-8 항상 정답 :

키 라인없는 선택 : 아직

Encoding encode = System.Text.Encoding.GetEncoding("windows-1255"); 
StreamReader readStream = new StreamReader(ReceiveStream, encode); 
+0

초기 질문을 편집하여 같은 문제가있는 다른 사람들을위한 해결책으로 추가하십시오. – Marcote