Most of the time we read the TXT with the traceprint output after the head will be inexplicably more than a question mark but you use a question mark to match him but the match is not an unknown character what is this, how to avoid this thing?
This is primarily a TXT file exists a BOM header string but in the Android state TXT does not recognize the string this BOM header is not visible in the computer
Treatment methods
1 Use an editing tool like noytepad++ to remove the BOM header from the TXT file and then upload this txt to Android to start the scripting process
2 The script reads txt every time it detects the existence of a BOM header string exists in the file content is not a better
The first way, I don't have to show myself to handle it.
The second I was using a function to implement the processing can be referred to below
Function text file format operation (file path) Dim read content read content=Trim (file. Read (file path))//determine if the first 3 characters are BOM header if Mid (read content,1,3) = CHR (239) & Chr (187) & Chr (191) Then//Yes, replace with empty and then re-write the content. This place is not sure if the BOM header may be there, except for the first line. File. Write file path, Replace (read content, CHR (239) & Chr (187) & Chr (191),"") End If//if the TXT in the end is not the end of the automatic add a carriage return newline character to implement this also resolves the replacement of the last line does not write \ r \ n will replace the case is not found If trim (read content)<>"" andRight (read the contents,2) <>"\ r \ n"Then file. Write file path, read content &"\ r \ n"End If End Function
Android key: Read the problem of unknown characters at the beginning of txt