Class Code128GS1Parser
GS1 Code128 parser that handles all GS1 Application Identifiers, validates data content, and provides comprehensive error handling. Supports multiple input formats and provides detailed parsing results.
Inheritance
Namespace: IronBarCode
Assembly: IronBarCode.dll
Syntax
public static class Code128GS1Parser : Object
When a GS1 Code 128 string needs validating, formatting, or breaking into its application identifiers, Code128GS1Parser does the work. Every member is static, so call the methods directly without constructing an instance. GS1 encodes structured data, such as a GTIN, batch, and expiry, into one Code 128 string using application identifiers, and this parser reads that structure back out.
Parse takes a GS1 input string and returns a ParseResult describing the parsed content, while ParseWithEncoding does the same and can include encoding detail through its includeEncoding flag. IsValid returns a bool for a quick conformance check before encoding or storing a value, and Format returns a normalized string form of the input. ExtractElements returns a List<ParsedElement>, one entry per application identifier and its value, which is the method to reach for when an application needs each field separately. GetEncodingInfo returns a Code128EncodingInfo for the input, with an isGS1 flag to indicate GS1 handling. To generate a GS1 Code 128 code rather than parse one, use BarcodeWriter.CreateBarcode with BarcodeEncoding.Code128GS1.
using IronBarCode;
if (Code128GS1Parser.IsValid(input))
{
ParseResult result = Code128GS1Parser.Parse(input);
}The create 1D barcodes how-to generates Code 128 codes, and the checksum and format validation how-to covers validating encoded values.
Methods
ExtractElements(String)
Extracts all GS1 elements from a string.
Declaration
public static List<ParsedElement> ExtractElements(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The GS1 string to parse. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<ParsedElement> | List of parsed GS1 elements. |
Exceptions
| Type | Condition |
|---|---|
| IronBarCodeParsingException | Thrown when the input cannot be parsed successfully due to validation errors. |
Format(String)
Formats a GS1 string
Declaration
public static string Format(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | The GS1 string to format. |
Returns
| Type | Description |
|---|---|
| System.String | Formatted GS1 string with parentheses. |
Remarks
This method throws an exception if the input is invalid.
Exceptions
| Type | Condition |
|---|---|
| IronBarCodeParsingException | Thrown when the input cannot be parsed successfully due to validation errors. |
GetEncodingInfo(String, Boolean)
Gets just the encoding information without full GS1 parsing. Useful for analyzing non-GS1 Code 128 barcodes.
Declaration
public static Code128EncodingInfo GetEncodingInfo(string input, bool isGS1 = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The barcode data to analyze. |
| System.Boolean | isGS1 | Whether this is a GS1-128 barcode. |
Returns
| Type | Description |
|---|---|
| Code128EncodingInfo | Code128EncodingInfo containing segment information. |
IsValid(String)
Validates if a string is a valid GS1 format
Declaration
public static bool IsValid(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The string to validate. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if valid GS1 format; false otherwise. |
Parse(String)
Parses and formats a GS1 string, handling multiple input formats and providing comprehensive validation.
Declaration
public static ParseResult Parse(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The GS1 string to parse (raw, formatted, or mixed). |
Returns
| Type | Description |
|---|---|
| ParseResult | ParseResult containing formatted string, elements, and validation results. |
Remarks
This method validates the GS1 structure and data content. If any validation errors occur, an IronBarCodeParsingException will be thrown with details about the specific errors.
Exceptions
| Type | Condition |
|---|---|
| IronBarCodeParsingException | Thrown when the input cannot be parsed successfully due to validation errors. The exception contains detailed information about all parsing errors encountered. |
ParseWithEncoding(String, Boolean)
Parses a GS1 string and includes Code 128 encoding analysis.
Declaration
public static ParseResult ParseWithEncoding(string input, bool includeEncoding = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The GS1 string to parse. |
| System.Boolean | includeEncoding | Whether to include Code 128 encoding segment analysis. |
Returns
| Type | Description |
|---|---|
| ParseResult | ParseResult with both logical (AI) and physical (encoding) information. |