Class GS1Parser
Parses and formats GS1 Application Identifier (AI) strings.
Inherited Members
Namespace: DRIT.Barcode.GS1
Assembly: DRIT.Barcode.dll
Syntax
public static class GS1Parser
Fields
Fnc1Char
The FNC1 escape character used in codetext strings (U+00F1, matching Code128Engine.EscapeFnc1).
Declaration
public const char Fnc1Char = 'ñ'
Field Value
| Type | Description |
|---|---|
| char |
GsChar
The GS (Group Separator) character used in decoded GS1 data.
Declaration
public const char GsChar = '\u001d'
Field Value
| Type | Description |
|---|---|
| char |
Methods
Format(List<GS1Field>)
Formats a list of GS1 fields into parentheses notation.
Declaration
public static string Format(List<GS1Field> fields)
Parameters
| Type | Name | Description |
|---|---|---|
| List<GS1Field> | fields |
Returns
| Type | Description |
|---|---|
| string |
GetIdentifier(string)
Gets the GS1ApplicationIdentifier for the specified AI string.
Declaration
public static GS1ApplicationIdentifier GetIdentifier(string ai)
Parameters
| Type | Name | Description |
|---|---|---|
| string | ai | The AI string (2, 3, or 4 digits). |
Returns
| Type | Description |
|---|---|
| GS1ApplicationIdentifier | The identifier descriptor. |
Exceptions
| Type | Condition |
|---|---|
| BarcodeException | The AI is not recognized. |
Parse(string)
Parses a GS1 string in parentheses or bracket notation into a list of fields. Example: "(01)12345678901231(10)LOT123" → 2 fields.
Declaration
public static List<GS1Field> Parse(string gs1String)
Parameters
| Type | Name | Description |
|---|---|---|
| string | gs1String | The GS1 string in parentheses or bracket notation. |
Returns
| Type | Description |
|---|---|
| List<GS1Field> | The parsed fields. |
Exceptions
| Type | Condition |
|---|---|
| BarcodeException | The string is not valid GS1 notation. |
ParseRaw(string)
Parses raw GS1 data (without parentheses) that uses FNC1 or GS as field separators.
Declaration
public static List<GS1Field> ParseRaw(string raw)
Parameters
| Type | Name | Description |
|---|---|---|
| string | raw | The raw GS1 data string. |
Returns
| Type | Description |
|---|---|
| List<GS1Field> | The parsed fields. |
Exceptions
| Type | Condition |
|---|---|
| BarcodeException | The raw data is not valid GS1 data. |
ToRawCodetext(List<GS1Field>)
Converts a list of GS1 fields into raw codetext with FNC1 separators. FNC1 is inserted after variable-length fields (except the last field).
Declaration
public static string ToRawCodetext(List<GS1Field> fields)
Parameters
| Type | Name | Description |
|---|---|---|
| List<GS1Field> | fields |
Returns
| Type | Description |
|---|---|
| string |
ToRawCodetext(string)
Converts a parentheses-notation GS1 string into raw codetext with FNC1 separators.
Declaration
public static string ToRawCodetext(string gs1String)
Parameters
| Type | Name | Description |
|---|---|---|
| string | gs1String |
Returns
| Type | Description |
|---|---|
| string |
TryGetIdentifier(string, out GS1ApplicationIdentifier?)
Tries to get the GS1ApplicationIdentifier for the specified AI string.
Declaration
public static bool TryGetIdentifier(string ai, out GS1ApplicationIdentifier? identifier)
Parameters
| Type | Name | Description |
|---|---|---|
| string | ai | The AI string. |
| GS1ApplicationIdentifier | identifier | The identifier, or null if not found. |
Returns
| Type | Description |
|---|---|
| bool | True if the AI was recognized. |