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

Problem importing text file with null value

New Here ,
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

I used the following codes to import a text file and it worked perfectly.
However, it skipped the TAB (chr(9)) on the imported row when there is no data (empty string) in one of the columns.
Can someone help? thanks!

sample text file data:
00001 desc1 12.00
00002 25.00
00003 desc2 15.00

Code that I used:
<cffile action="read" file="#FilePath#" variable="data">
<cfset newLine = chr(13) & chr(10)>
<cfset tabChar = chr(9)>

<cfoutput>
<cfloop list="#data#" index="row" delimiters="#newLine#">
<cfset cols = listToArray(row, tabChar)>

ID = #cols[1]#
desc = #cols[2]#
price = #cols[3]# <br>
</cfloop>
</cfoutput>
TOPICS
Advanced techniques

Views

355

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
Advisor ,
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

There is no perfect way to handle this with out you writing more complicated code.

A good compromise is to replace this line:
<cfset cols = listToArray(row, tabChar)>

with this:
<cfset cols = listToArray (Replace (row, tabChar & tabChar, tabChar & "{empty}" & tabChar, "ALL"), tabChar)>

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
New Here ,
Jun 07, 2006 Jun 07, 2006

Copy link to clipboard

Copied

Wow...it worked! thanks sooooo much!!

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
New Here ,
Jun 07, 2006 Jun 07, 2006

Copy link to clipboard

Copied

LATEST
Yes, Thank you as well!!

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
Resources
Documentation