Table of Contents

Class DelimitedStringOptions

Namespace
Cuemon
Assembly
Cuemon.Core.dll
public class DelimitedStringOptions : FormattingOptions, IValidatableParameterObject, IParameterObject
Inheritance
DelimitedStringOptions
Implements
Inherited Members

Examples

The following example demonstrates how to use to configure custom delimiters and qualifiers when parsing delimited strings using .

using System;
using Cuemon; // for DelimitedStringOptions, DelimitedString

namespace MyApp.Examples;

public class DelimitedStringOptionsExample
{
    public void Demonstrate()
    {
        // Default options: comma delimiter, double-quote qualifier
        var defaultOptions = new DelimitedStringOptions();
        Console.WriteLine($"Delimiter: '{defaultOptions.Delimiter}'"); // ','
        Console.WriteLine($"Qualifier: '{defaultOptions.Qualifier}'"); // '"'

        // Custom tab-delimited options
        var tabOptions = new DelimitedStringOptions
        {
            Delimiter = "\t",
            Qualifier = "'"
        };

        // Parse a tab-delimited line using the setup action
        string tabLine = "Alice\t30\tNew York";
        string[] fields = DelimitedString.Split(tabLine, o =>
        {
            o.Delimiter = tabOptions.Delimiter;
            o.Qualifier = tabOptions.Qualifier;
        });
        Console.WriteLine($"Fields: {string.Join(", ", fields)}"); // Alice, 30, New York

        // Parse a pipe-delimited line
        string pipeLine = "'Bob'|'25'|'London'";
        fields = DelimitedString.Split(pipeLine, o =>
        {
            o.Delimiter = "|";
            o.Qualifier = "'";
        });
        Console.WriteLine($"Fields: {string.Join(", ", fields)}"); // Bob, 25, London

}
}

Constructors

DelimitedStringOptions()

Initializes a new instance of the DelimitedStringOptions class.

public DelimitedStringOptions()

Remarks

The following table shows the initial property values for an instance of DelimitedStringOptions.

PropertyInitial Value
Delimiter,
Qualifier"
FormatProviderInvariantCulture

Properties

Delimiter

Gets or sets the delimiter that separates the fields. Default is comma (,).

public string Delimiter { get; set; }

Property Value

string

The delimiter that separates the fields.

Qualifier

Gets or sets the qualifier placed around each field to signify that it is the same field. Default is quotation mark (").

public string Qualifier { get; set; }

Property Value

string

The qualifier placed around each field to signify that it is the same field.

Methods

ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.

public override void ValidateOptions()

Remarks

This method is expected to throw exceptions when one or more conditions fails to be in a valid state.