Class SwiftTextLines
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
sLinestring
SwiftTextLines(string, bool)
public SwiftTextLines(string sText, bool fNewLine)
Parameters
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
sTextstringThe text that makes up the new text block. If this is
null, then the new text block will be empty.nMaxCharsintThe 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.
fNewLineboolIf
true, then the text will be splt at new line sequences.fWordWrapboolIf
true, then long lines will be broken up at a blank character, if possible. Iffalse, 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
vsLinesstring[]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
this[int]
Direct access to the individual lines in this text block.
public string this[int nIndex] { get; set; }
Parameters
nIndexintThe index of the line to retrieve. If this is greater than the number of lines available, then
nullis returned.
Property Value
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
Methods
AddEmptyLine()
public void AddEmptyLine()
AddLine(string)
Add a single line at the end of this text block.
public void AddLine(string sLine)
Parameters
sLinestringThe line to be added. If this is
nullor 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
sLinestringThe line to be added.
fAddEmptyLinesboolIf this is
true, then an empty string ornullwill add an empty line. If this isfalse, then an empty string ornullwill 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
sLinestringThe line to be added. If this is
nullor an empty string, then nothing will be added.nMaxCharsintThe 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.
nWrapOptionSwiftTextLines.WrapOptionSelects how to break a line that is longer than
nMaxCharscharacters.
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
sLinestringThe line to be added. If this is
nullor an empty string, then nothing will be added.nMaxCharsintThe 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.
fWordWrapboolIf
true, then any leading or trailing whitespace will be trimmed and long lines will be broken up at a blank character, if possible. Iffalse, 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
vsLinesstring[]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
sTextstring
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
sTextstringThe text to be added.
nMaxCharsintThe 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.
fNewLineboolIf
true, then the text will be split at new line sequences.fWordWrapboolIf
true, then long lines will be broken up at a blank character, if possible. Iffalse, 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
nMaxCharsintThe maximum allowed line length. Lines longer than this length will be broken into multiple adjacent lines.
nMaxLinesintThe 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
CompareTo(SwiftTextLines)
public int CompareTo(SwiftTextLines that)
Parameters
thatSwiftTextLines
Returns
CompareTo(object)
public int CompareTo(object obj)
Parameters
objobject
Returns
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
GetEnumerator()
public IEnumerator GetEnumerator()
Returns
GetHashCode()
public override int GetHashCode()
Returns
IsEmpty()
public bool IsEmpty()
Returns
Join(string)
public string Join(string sNewLine = "")
Parameters
sNewLinestring
Returns
Pack()
Packs all lines onto a single text line, replacing any new line sequences with a single blank character.
public string Pack()
Returns
Pack(int)
Packs all lines onto a single text line without any new line sequence.
public string Pack(int nMaxChars)
Parameters
nMaxCharsintMaximum number of characters of a packed line.
Returns
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
Returns
RemoveAt(int)
public void RemoveAt(int nIndex)
Parameters
nIndexint
Exceptions
- ArgumentOutOfRangeException
A line with the given index does not exist in this instance.
SetLineCount(int)
public void SetLineCount(int nLineCount)
Parameters
nLineCountint
SetLines(string[])
Set the content of this text block from an array of strings.
public void SetLines(string[] vsLines)
Parameters
vsLinesstring[]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
sTextstring
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
sTextstringThe text to be set.
nMaxCharsintThe 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.
fNewLineboolIf
true, then the text will be splt at new line sequences.fWordWrapboolIf
true, then long lines will be broken up at a blank character, if possible. Iffalse, then lines will be broken up into exactly nMaxChars portions.
Exceptions
- ArgumentException
The parameter sNewLine was an empty string. Use
nullif 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
TrimLines()
public void TrimLines()
TrimTrailingEmptyLines()
public void TrimTrailingEmptyLines()
Operators
operator ==(SwiftTextLines, SwiftTextLines)
public static bool operator ==(SwiftTextLines lhs, SwiftTextLines rhs)
Parameters
lhsSwiftTextLinesrhsSwiftTextLines
Returns
operator !=(SwiftTextLines, SwiftTextLines)
public static bool operator !=(SwiftTextLines lhs, SwiftTextLines rhs)
Parameters
lhsSwiftTextLinesrhsSwiftTextLines