Row

Row operations consist of the filters, transformers, and bufferings. Each of these are described in Basics and Reference documentation. Pnyx will automatically Shim Line operations (filters and transformers) whenever calling Line methods while in Row state. In addition to these operations, the following operations are available: The rest of this page illustrates some usages these operations.

Shim Examples

By default, when shimming Line filters, a boolean OR operation is performed. This means that a Row will be matched, if any column matches the ILineFilter. To match each column, use the shimAnd method. An example of both are shown below.
Shim OR:
            
const String input = @"Line one,a,,c
Line two,a,b,c
Line three,,,c
"; 
await using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.hasLine();
    p.writeStdout();
}                        
// outputs:
// "Line one",a,,c
// "Line two",a,b,c
// "Line three",,,c
Shim AND:
const String input = @"Line one,a,,c
Line two,a,b,c
Line three,,,c
"; 
await using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.shimAnd(p2 => p2.hasLine());
    p.writeStdout();
}                        
// outputs:
// "Line two",a,b,c

Custom Operations

The built-in Row opertions for Pnyx only cover the very basics. For any advanced application, custom operations will be used extensively. In this case, each Row interface is simple to implement and easily tested with Unit Tests. In addition to implementing interfaces, Pnyx supports using Lambda expression for quicker, more flexible usage. The following examples shows the two Row operations with Lambda expressions.

rowFilter (lambda):
const String input = @"Line one,KEEPER
Line two,Loser
"; 
await using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.rowFilter(x => x[1].isUpperCase());
    p.writeStdout();
}                        
// outputs:         
// "Line one",KEEPER
rowTransformer (lambda):
const String input = @"Line one,KEEPER
Line two,LOSER
"; 
await using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.rowTransformer(x => new List<string?> {x[1].toTitleCase()});
    p.writeStdout();
}                        
// outputs:            
// Keeper
// Loser

Convert To Line

To convert Row data to Line data, there are several methods available. These methods: print, printDelimiter, and printTab are documented in Reference, Conversion. For advanced formatting, IRowConverter should be implemented and used with rowToLine method. Below are some examples of converting Row data to Line data.
print
const String input = "Socialism,Communism,Fascism"; 
await using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.print("Failed Systems: $1, $2, and $3");
    p.writeStdout();
}                        
// outputs: Failed Systems: Socialism, Communism, and Fascism
printDelimiter
const String input = "col1,\"Column, zwei\""; 
await using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.printDelimiter("|");
    p.writeStdout();
}                        
// outputs: col1|Column, zwei

Next

Suggested next steps:
  • Line, learn more about Line operations
  • Object, examples of Object operations
  • NameValuePair, examples of Name-Value Pair operations
  • Input, learn more about Input operations
  • Output, learn more about Output operations