Hi

leading zeros removed but then still ensure it becomes a fixed 13-digit barcode

 string barcodes = string.Join(",",

    result.data.Select(a =>

    {

        if (long.TryParse(a.BarcodeValue, out long num))

        {

            // Remove leading zeros by parsing, then ensure 13-digit format

            return num.ToString().PadLeft(13, '0');

        }

        return a.BarcodeValue; // fallback if not purely numeric

    })

);


Example:

Input → ["0507510108257", "0001234", "7890"]

Output →

0507510108257,000000001234,000000007890

This way you always get exactly 13 digits, even after trimming the original zeros.
Previous
Next Post »