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
"; 
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
"; 
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 Test. 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.

rowFilterFunc:
const String input = @"Line one,KEEPER
Line two,Loser
"; 
using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.rowFilterFunc(x => TextUtil.isUpperCase(x[1]));
    p.writeStdout();
}                        
// outputs:         
// "Line one",KEEPER
rowTransformerFunc:
const String input = @"Line one,KEEPER
Line two,LOSER
"; 
using (Pnyx p = new Pnyx())
{
    p.readString(input);
    p.parseCsv();
    p.rowTransformerFunc(x => new List<string> {NameUtil.toTitleCase(x[1])});
    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, Line, Row 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"; 
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\""; 
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
  • Input, learn more about Input operations
  • Output, learn more about Output operations