Haskell IO Russian characters

I am trying to execute a process file that is written in Russian characters. When you read and after writing text to a file, I get something like:

"\ 160 \ 192 \ 231 \ 229 \ 240 \ 225 \ 224 \ 233 \ 228 \ 230 \ 224 \ 237"

How can I get normal characters?

thanks

+4
source share
3 answers

I have success.

{-# LANGUAGE ImplicitParams #-} import Network.HTTP import Text.HTML.TagSoup import Data.Encoding import Data.Encoding.CP1251 import Data.Encoding.UTF8 openURL x = do x <- simpleHTTP (getRequest x) fmap (decodeString CP1251) (getResponseBody x) main :: IO () main = do tags <- fmap parseTags $ openURL "http://www.trade.su/search?ext=1" let TagText r = partitions (~== "<input type=checkbox>") tags !! 1 !! 4 appendFile "out" r 
+1
source

If you get lines with backslashes and numbers, then it looks like you can call "print" when you want to call "putStr".

+4
source

If you work with Unicode, you can try the utf8-string package

 import System.IO hiding (hPutStr, hPutStrLn, hGetLine, hGetContents, putStrLn) import System.IO.UTF8 import Codec.Binary.UTF8.String (utf8Encode) main = System.IO.UTF8.putStrLn " " 

However, this did not work in my CLI window, which distorts the output due to the code page. I expect it to work fine on other Unix-like systems if your language is installed correctly. However, writing to a file must be successful on all systems.

UPDATE:

An example for using a coding package.

+2
source

Source: https://habr.com/ru/post/1309859/


All Articles