Class SwiftTextLines

Namespace
Subsembly.Swift
Assembly
Subsembly.Sepa.dll

Helper class for working with a block of text lines, such as the multi-line payment purpose field on a German remittance.

public class SwiftTextLines : IEnumerable<string>, IEnumerable, IComparable, IComparable<SwiftTextLines>
Inheritance
SwiftTextLines
Implements
Inherited Members

Remarks

This class manages a multi-line text field as an conceptual array of strings. It ensures that leading and trailing whitespace is trimmed from all the lines that it contains. Also, it ensures that it never contains empty lines or even null string references.

Constructors

SwiftTextLines()

Constructs an all empty instance.

public SwiftTextLines()

SwiftTextLines(string)

Constructs a new instance containing a single line of text.

public SwiftTextLines(string sLine)

Parameters

sLine string

SwiftTextLines(string, bool)

public SwiftTextLines(string sText, bool fNewLine)

Parameters

sText string
fNewLine bool

SwiftTextLines(string, int, bool, bool)

Constructs a new instance by splitting up a single text string.

public SwiftTextLines(string sText, int nMaxChars, bool fNewLine, bool fWordWrap)

Parameters

sText string

The text that makes up the new text block. If this is null, then the new text block will be empty.

nMaxChars int

The max number of characters that may be placed on a single line. If the given line exceeds this limit, then it will be broken up into multiple lines.

fNewLine bool

If true, then the text will be splt at new line sequences.

fWordWrap bool

If true, then long lines will be broken up at a blank character, if possible. If false, then lines will be broken up into exactly nMaxChars portions.

Exceptions

ArgumentOutOfRangeException

The parameter nMaxChars was zero or negative.

SwiftTextLines(string[])

Constructs a new instance from an array of strings.

public SwiftTextLines(string[] vsLines)

Parameters

vsLines string[]

Array of strings that provides the initial content of this text block. If this parameter is null, then the new text block will be empty. Otherwise all non-empty and non-null strings contained in the array are trimmed and become the content of the new text block.

Properties

Count

The actual count of lines.

public int Count { get; }

Property Value

int

this[int]

Direct access to the individual lines in this text block.

public string this[int nIndex] { get; set; }

Parameters

nIndex int

The index of the line to retrieve. If this is greater than the number of lines available, then null is returned.

Property Value

string

Exceptions

ArgumentOutOfRangeException

The given index was less than zero.

MaxChars

Provides the number of characters in the longest line contained in this text lines instance.

public int MaxChars { get; }

Property Value

int

Methods

AddEmptyLine()

public void AddEmptyLine()

AddLine(string)

Add a single line at the end of this text block.

public void AddLine(string sLine)

Parameters

sLine string

The line to be added. If this is null or an empty string, then nothing will be added.

AddLine(string, bool)

Add a single line at the end of this text block.

public void AddLine(string sLine, bool fAddEmptyLines)

Parameters

sLine string

The line to be added.

fAddEmptyLines bool

If this is true, then an empty string or null will add an empty line. If this is false, then an empty string or null will be ignored.

AddLine(string, int, WrapOption)

Adds a single text line at the end of this text block.

public void AddLine(string sLine, int nMaxChars, SwiftTextLines.WrapOption nWrapOption)

Parameters

sLine string

The line to be added. If this is null or an empty string, then nothing will be added.

nMaxChars int

The max number of characters that may be placed on a single line. If the given line exceeds this limit, then it will be broken up into multiple lines.

nWrapOption SwiftTextLines.WrapOption

Selects how to break a line that is longer than nMaxChars characters.

Exceptions

ArgumentOutOfRangeException

The parameter nMaxChars was zero or negative.

AddLine(string, int, bool)

Adds a single text line at the end of this text block.

public void AddLine(string sLine, int nMaxChars, bool fWordWrap)

Parameters

sLine string

The line to be added. If this is null or an empty string, then nothing will be added.

nMaxChars int

The max number of characters that may be placed on a single line. If the given line exceeds this limit, then it will be broken up into multiple lines.

fWordWrap bool

If true, then any leading or trailing whitespace will be trimmed and long lines will be broken up at a blank character, if possible. If false, then lines will be broken up into exactly nMaxChars portions.

Exceptions

ArgumentOutOfRangeException

The parameter nMaxChars was zero or negative.

AddLines(string[])

public void AddLines(string[] vsLines)

Parameters

vsLines string[]

Array of strings that provides the text lines to be added. If this parameter is null, then nothing will be added. Otherwise all non-empty and non-null strings contained in the array are trimmed and added to this text block.

AddText(string)

public void AddText(string sText)

Parameters

sText string

AddText(string, int, bool, bool)

Add the given text wrapping it over mutliple lines if necessary.

public void AddText(string sText, int nMaxChars, bool fNewLine, bool fWordWrap)

Parameters

sText string

The text to be added.

nMaxChars int

The max number of characters that may be placed on a single line. If a line exceeds this limit, then it will be broken up into multiple lines.

fNewLine bool

If true, then the text will be split at new line sequences.

fWordWrap bool

If true, then long lines will be broken up at a blank character, if possible. If false, then lines will be broken up into exactly nMaxChars portions.

Exceptions

ArgumentOutOfRangeException

The parameter nMaxChars was zero or negative.

BreakLines(int, int)

Breaks all lines that are longer than the requested max line length into multiple adjacent lines.

public void BreakLines(int nMaxChars, int nMaxLines = 0)

Parameters

nMaxChars int

The maximum allowed line length. Lines longer than this length will be broken into multiple adjacent lines.

nMaxLines int

The max number of resulting lines after breaking them. Any excess lines are discarded in order to match this limit. If this is zero, then no max line limit will be applied.

Remarks

The lines will be broken hard at the nMaxChars position. No trimming of leading or trailing whitespace will be done. Thus all whitespace is preserved exactly.

Clear()

Clear this text block.

public void Clear()

Clone()

public SwiftTextLines Clone()

Returns

SwiftTextLines

CompareTo(SwiftTextLines)

public int CompareTo(SwiftTextLines that)

Parameters

that SwiftTextLines

Returns

int

CompareTo(object)

public int CompareTo(object obj)

Parameters

obj object

Returns

int

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetEnumerator()

public IEnumerator GetEnumerator()

Returns

IEnumerator

GetHashCode()

public override int GetHashCode()

Returns

int

IsEmpty()

public bool IsEmpty()

Returns

bool

Join(string)

public string Join(string sNewLine = "")

Parameters

sNewLine string

Returns

string

Pack()

Packs all lines onto a single text line, replacing any new line sequences with a single blank character.

public string Pack()

Returns

string

Pack(int)

Packs all lines onto a single text line without any new line sequence.

public string Pack(int nMaxChars)

Parameters

nMaxChars int

Maximum number of characters of a packed line.

Returns

string

Remarks

All lines are joined using the blank character between each line. If a line fills the entire MaxChars, then no blank is appended and it is directly concatenated with the subsequent line.

PackLines(int, int)

Nicely wraps lines to match the requested max line length.

public bool PackLines(int nMaxChars, int nMaxLines)

Parameters

nMaxChars int
nMaxLines int

Returns

bool

RemoveAt(int)

public void RemoveAt(int nIndex)

Parameters

nIndex int

Exceptions

ArgumentOutOfRangeException

A line with the given index does not exist in this instance.

SetLineCount(int)

public void SetLineCount(int nLineCount)

Parameters

nLineCount int

SetLines(string[])

Set the content of this text block from an array of strings.

public void SetLines(string[] vsLines)

Parameters

vsLines string[]

Array of strings that provides the new content of this text block. If this parameter is null, then this text block is effectively cleared. Otherwise all non-empty and non-null strings contained in the array are trimmed and become the new text block.

SetText(string)

Set text with new lines but without word wrapping.

public void SetText(string sText)

Parameters

sText string

SetText(string, int, bool, bool)

Set this text block to the given text, wrapping it over mutliple lines if necessary.

public void SetText(string sText, int nMaxChars, bool fNewLine, bool fWordWrap)

Parameters

sText string

The text to be set.

nMaxChars int

The max number of characters that may be placed on a single line. If a line exceeds this limit, then it will be broken up into multiple lines.

fNewLine bool

If true, then the text will be splt at new line sequences.

fWordWrap bool

If true, then long lines will be broken up at a blank character, if possible. If false, then lines will be broken up into exactly nMaxChars portions.

Exceptions

ArgumentException

The parameter sNewLine was an empty string. Use null if you do not want to split at newline sequences.

ArgumentOutOfRangeException

The parameter nMaxChars was zero or negative.

ToArray()

public string[] ToArray()

Returns

string[]

ToString()

public override string ToString()

Returns

string

TrimLines()

public void TrimLines()

TrimTrailingEmptyLines()

public void TrimTrailingEmptyLines()

Operators

operator ==(SwiftTextLines, SwiftTextLines)

public static bool operator ==(SwiftTextLines lhs, SwiftTextLines rhs)

Parameters

lhs SwiftTextLines
rhs SwiftTextLines

Returns

bool

operator !=(SwiftTextLines, SwiftTextLines)

public static bool operator !=(SwiftTextLines lhs, SwiftTextLines rhs)

Parameters

lhs SwiftTextLines
rhs SwiftTextLines

Returns

bool