• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Import from text file problem with first line od data

Explorer ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

I have a little problem with importing data from a text file.
I have a file with exported data from documents. Each line in the file consists of a field name, a separator (here, for example, "::") and the contents of the field.
I point to the file with

 

 

var rStream = util.readFileIntoStream();

 

 

I read its content

 

 

var cFile = util.stringFromStream(rStream, "utf-16");

 

 

The file is saved with UTF-16 encoding.
Then there is the processing of the read text line by line.

I split the file into lines using .split('\r\n') and then the lines into fields using .split('::') And here comes the problem, all lines of data except the first load fine.
The first line contains the text:
Organ_Nazwa::Urzad Miasta
However, for the script, the beginning of this line is different and is not the same as the "Organ_Nazwa" string, even though it is visible. However, I just add a blank line at the beginning of the file and everything is OK.
Everything looks exactly the same in the debugger, but it's not. It looks as if this string from the beginning of the file contains some white space at the beginning.

TOPICS
JavaScript , PDF forms

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 06, 2022 Dec 06, 2022

I dealt with this issue in the past so I'll save you a lot of headaches and provide the solution. Many text files contain something called a BOM (Byte Order Mark) which is a zero-width unicode character. The reason for it is not important, but it's always the first character in the file, and needs to be removed manually if you want the text in the first line to match your field names, for example.

To do so use the following command:

cFile = cFile.replace("\uFEFF", "");

Votes

Translate

Translate
Community Expert ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

I dealt with this issue in the past so I'll save you a lot of headaches and provide the solution. Many text files contain something called a BOM (Byte Order Mark) which is a zero-width unicode character. The reason for it is not important, but it's always the first character in the file, and needs to be removed manually if you want the text in the first line to match your field names, for example.

To do so use the following command:

cFile = cFile.replace("\uFEFF", "");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

Thanks for the answer, the .trim() function also gives the right result.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

LATEST

Yes, but be aware it will not work in older versions of Acrobat or Reader.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines