Android key: Read the problem of unknown characters at the beginning of txt

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.