Skip to main content
Known Participant
October 20, 2009
Question

Can we count tabs?

  • October 20, 2009
  • 2 replies
  • 1019 views

I'm writing CF application where my user is upoading a tab delimited text file.

From past experience, many times users uploaded a text file with less tabs and causing chaos.

The first thing that came to my mind was to count the tabs, if they don't match the total tabs requirements than I should write to reject this file being uploaded.

I'm not sure how can I count tabs, does anyone has some code example?

Thank you!

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
October 24, 2009

<cfsavecontent variable="content">
1    a12    a13
2    a22        a23    a24
3    a32        a33
4    a42    a43
</cfsavecontent>
<!--- loop thru content, line by line --->
<cfloop list="#content#" index="line" delimiters="#chr(13)##chr(10)#">
    <!--- replace each tab with a comma (note that there is a space before and after the comma)  --->
    <cfset line = replace(line,chr(9)," , ","all")>
<br>line: <cfoutput>#line#</cfoutput><br>
number of delimiters: <cfoutput>#listlen(line)-1#</cfoutput><br>
</cfloop>

Inspiring
October 20, 2009

listlen(LineOfText, chr(9))

Inspiring
October 20, 2009

listlen(LineOfText, chr(9))

Not so good if there are runs of tabs.

Perhaps best to replace all the tabs with nowt, and then check the difference between the source string and result string.

--

Adam

aleckenAuthor
Known Participant
October 21, 2009

what is nowt?