Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Export-csv changing names with apostrophes

$
0
0

Strange, yes, but there’s not much I can do to troubleshoot that from here. First thing I would do is check to see if that string contains any multi-byte characters, and then check the encoding of the CSV file. Here’s a quick example of one way to test for that, and several examples of Unicode characters that look similar to the ASCII apostrophe:

function ContainsMultiByteCharacters ([string] $String)
{
    if ($null -eq $String) { return $false }
    return [System.Text.Encoding]::UTF8.GetByteCount($String) -ne $String.Length
}

[char[]]$chars = [char]0x02BC, [char]0x275C, [char]0x2019, "'"
$string1 = New-Object string (,$chars)
$string2 = "Just a plain old string."


New-Object psobject -Property @{
    String = $string1
    ContainsMultiByteCharacters = ContainsMultiByteCharacters $string1
}

New-Object psobject -Property @{
    String = $string2
    ContainsMultiByteCharacters = ContainsMultiByteCharacters $string2
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles