locked
parsing file with non-English characters as single string RRS feed

  • Question

  • Using Powershell 1 or 2

    I want to parse a file and create strings based on various delimiters, particularly using regular expression captures, instead of reading one line at a time (delimited by the new line character). So, I want to read in my entire file in. So, I read that I can use [System.IO.File]::ReadAllText(). This seems to work if I use a file with only English characters, but if I use a file with accents, French in particular, it kills all the accented characters. If I simply output this to another file, I get a bunch of ? or however the viewing application wants to render those characters.

    Get-Content does not munge the data, but it will read the file as one line at time. Even if I use the -ReadCount 0 option, it still does not do what I want, or does it?
    Saturday, December 12, 2009 7:32 PM

Answers

  • [string](get-content file.txt)

    will read the file in as a single string, with a space (or whatever the curret OFS is) between each line.  If you want to get rid of the space, set $OFS to "" first.
    • Marked as answer by notRoman Monday, December 21, 2009 6:33 AM
    Sunday, December 13, 2009 2:16 PM