String length when converting from a character array

后端 未结 4 671
耶瑟儿~
耶瑟儿~ 2020-12-06 20:08

I\'m having serious problems with string-handling. As my problems are rather hard to describe, I will start with some demo code reproducing them:

Dim s1 As S         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 21:06

    If you want to create strings from a byte array, i.e. ID3v2.4.0 with ISO-8859 encoding, then this should work:

        Dim s1 As String = "Test"
        Dim b() As Byte = New Byte() {84, 101, 115, 116, 0, 0, 0}
        Dim s2 As String = System.Text.ASCIIEncoding.ASCII.GetString(b).Trim(ControlChars.NullChar)
    
        If s1 = s2 Then Stop
    

    According to this http://id3.org/id3v2.4.0-structure other encodings may be present and the code would need to be adjusted if one of the others is used.

提交回复
热议问题