I have a Chinese txt file that reads garbled characters when using ReadMap, the solution is as follows: read it with ReadList and convert it to Map
B4X:
'将List转换成MAP
public Sub ListToMap(decList As List) As Map
Dim tmpMap As Map
tmpMap.Initialize
For Each s As String In decList
If s.Contains("=") Then
Dim MapSplit() As String=Regex.Split("\=",s)
If MapSplit.Length=1 Then
tmpMap.Put(MapSplit(0),"")
Else
tmpMap.Put(MapSplit(0),MapSplit(1))
End If
End If
Next
Return tmpMap
End Sub
'直接使用ReadMap会导致乱码
public Sub InitLanguage(Path As String,LanguageName As String) as Map
Dim LanguageFile As String=$"${LanguageName}.txt"$
Dim LangList As List
If File.Exists(Path,LanguageFile) Then
LangList=File.ReadList(Path,LanguageFile)
Return ListToMap(LangList)
End If
End Sub
Attachments
Last edited: