Coldfusion - Using ListFind and Split to get empty elements in a list

I am working with a lot of data import modules in ColdFusion and there are a lot of issues to handle while doing the import process. The data uploaded will be of different format, different delimiters, empty or null values etc. etc.
Here, I am describing a problem where the delimiter is tab and the first element is null. I had to check whether the first element is null. I tried using ListGetAt(stringVariable,1,Chr(9)). Now, what this returned was the first non-empty element and not possible to check whether the first element was null.


After a bit of googling, I found the string.split() function. This function will convert the delimited string to Array. This perfectly split each element with the delimiter and creates an array.
Syntax:
<cfoutput>#stringVariable.split(chr(9),-1)#</cfoutput>

We will get an array of all elements in the string even if they are empty. In this case, the array had first element empty string and it is easy to check whether it is empty or not.

Comments

Popular posts from this blog

Hide notification content in Android lock screen for Messages, email, whatsapp and selected apps.

Array functions in JavaScript