StringPolyfillExtensionReplaceLineEndings(String, String) Method

Replaces all newlines in s with replacementText.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static string ReplaceLineEndings(
	this string s,
	string replacementText
)

Parameters

s  String
The source String.
replacementText  String
The text to use as replacement. If replacementText is Empty, all newline sequences within s will be removed.

Return Value

String
A String whose contents match the content of s, but with all newline sequences replaced with replacementText.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This is a polyfill for the .NET 6.0 method String.ReplaceLineEndings(String). The method should therefore only be used in the extension method syntax. It throws a NullReferenceException if s is null in order to show identical behavior to the original .NET method.

The method searches for all newline sequences within s and canonicalizes them to match replacementText.

The list of recognized newline sequences is:

  • CR (U+000D)
  • LF (U+000A)
  • CRLF (U+000D U+000A)
  • NEL (U+0085)
  • LS (U+2028)
  • FF (U+000C)
  • PS (U+2029)

This list is specified by the Unicode standard (Sec. 5.8, Recommendation R4 and Table 5-2).

Exceptions

NullReferenceExceptions is null.
ArgumentNullExceptionreplacementText is null.

See Also