Counting Delimers in Flatfile

Hi All,

How to count delimers in flatfile.

My file is like–

abc,abc,abc,abc,abv

Regards
Hariom

Hi Hariom,

can you please explain the business case behind the need to count the delimites in a flat file?

You can check the PSUtilities Package (available from download section of the community) if there is a matching service.
I did not find one in the Built-In-Services reference.

One option might be to tokenize the record and then check for the length of the resulting list.
Number of delimiters is then (length - 1).

Regards,
Holger

Hi Holger,

I used tokenizer service also for this. but when any attribute comes ad null that time tokenizer is not useful,

like-- abc,abc,abc,abc

that resultset not counting null value.

My requirement is if delimeter (COMMA) is less than 29 then flatfile should be reject.

Regards
Hariom

Hi Hariom,

understand for double delimiters being ignored by tokenize.
Missing control parameter for “subsequent delimiters as one delimiter or several delimiiters” here in this case.

Why not have the FlatFIle schema convert all records to document and then validate this one, returning the invalid records?
If file structure is too bad converting from FlatFile to Document using schema will fail during conversion.

Please provide more details about flat file structure and amount of (different) records occurences.

Scenario still unclear why (pre-) validation shouid be done on this low level processing.

Regards,
Holger

Hi Holger,

Our requirement is - if the comma(delimeters) id equals to 28 then only i need to convert into values by convertTovalues service. if comma(delimeters) is than less than 28 then we need to reject the flatfile.

Regards
Hariom

Try this code:

IDataCursor pipelineCursor = pipeline.getCursor();
String inString = IDataUtil.getString( pipelineCursor, "inString" );
int temp=0;
pipelineCursor.destroy();

	for(int i = 0; i < inString.length(); i++) {
	    if(inString.charAt(i) == ',') temp++;
	}
	
	String count=Integer.toString(temp);
	
	
	// pipeline
	IDataCursor pipelineCursor_1 = pipeline.getCursor();
	IDataUtil.put( pipelineCursor_1, &quot;count&quot;, count );

Hi Mahesh,

I tried with your code.
My input variable is $xmldata like – abc,abc,abc,abc,abc

while Running i am not getting anything in result-

but when i run code in java its working fine.

Regards
Hariom

Hi Hariom,

assumiinng that there multiple lines in the flat file:
What should happen if some of them matches the required lenght of 29 fields and some do not?

For me it is still not clear why the flat file needs to be pre-validated und rejected maybe before converting to Document Structure.

It will be much easier when validating the Document structure and inform the provider that the flat file didn´t match the required structure.

Regards,
Holger

You have the code and try to debug the code to make it work (use it if only required). Also looking at the topic, get your requirement clarified and then start to build your solution.

I agree with Holger’s comments “For me it is still not clear why the flat file needs to be pre-validated und rejected maybe before converting to Document Structure. It will be much easier when validating the Document structure and inform the provider that the flat file didn´t match the required structure.”

Flat file convertToValues will perform more precise validation. Counting delimiters should not be necessary.

Just my two-cents.

-Mary

1 Like

Hi Holger,

My flatfile is like—
EMPID,EMPNAME,DOJ,EXPERIENCE,TECHNOLOGY------Fields Name-- (Always i will get 28 delimeter(comma))----first line of flatfile
1,Karan,2017-02-08,5years,WebMehtods---------------------------Fields Value–(I have a business requirement if thedelimeter is lessthan 28 than i need to reject the flatfile)

Regards
Hariom

Hi Hariom,

looks like this gets more and more complicated now.

Assuming that the FlatFile schema and the FlatFile dictionary are configured correctly (first line is header line; all fields are marked as required, but can be empty; …) then convertFlatFileToValues will do all neccesary validations and return an error message indicating missing fields

Addtionallly the approach for just counting the delimiters will only work when it is guaranteed that the fieilds values are not allowed to contain the delimiter character. If delimiter chatracter is allowed in fields content (contemt is usually enclosed in double quotes then) the counter for the delimiters might be returning the expected value, but in reality you are missing fields in your structure.

Regards,
Holger