X.Extensions.Text 3.3.2

Prefix Reserved
dotnet add package X.Extensions.Text --version 3.3.2                
NuGet\Install-Package X.Extensions.Text -Version 3.3.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="X.Extensions.Text" Version="3.3.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add X.Extensions.Text --version 3.3.2                
#r "nuget: X.Extensions.Text, 3.3.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install X.Extensions.Text as a Cake Addin
#addin nuget:?package=X.Extensions.Text&version=3.3.2

// Install X.Extensions.Text as a Cake Tool
#tool nuget:?package=X.Extensions.Text&version=3.3.2                

X.Extensions.Text

NuGet Version Twitter URL

The TextHelper class provides utility methods for common text manipulation tasks such as cleaning, substringing, replacing characters, and extracting keywords.

This library is designed to simplify text processing in .NET applications.

Installation

Include the X.Extensions.Text namespace in your project to use the TextHelper class.

using X.Extensions.Text;

Methods

Substring(string text, int length)

Retrieves a substring starting from the beginning of the given text, limited to the specified length.

Example
string text = "This is a long text.";
string result = TextHelper.Substring(text, 10);
Console.WriteLine(result); // Output: "This is a "

Substring(string text, int length, string endPart)

Retrieves a substring with the option to append a custom ending (e.g., "...") if the text is truncated.

Example
string text = "This is a long text.";
string result = TextHelper.Substring(text, 10, "...");
Console.WriteLine(result); // Output: "This is..."

CleanCharacters(string text)

Cleans system characters and replaces them with hyphens. Ensures no double spaces and trims the result.

Example
string text = "Hello, world! This is a test.";
string result = TextHelper.CleanCharacters(text);
Console.WriteLine(result); // Output: "hello-world-this-is-a-test"

Replace(string text, IEnumerable<string> targets, string replacement)

Replaces all occurrences of the specified target strings in the input text with the replacement string.

Example
string text = "Hello, world!";
string result = TextHelper.Replace(text, new[] { "Hello", "world" }, "Hi");
Console.WriteLine(result); // Output: "Hi, Hi!"

ToPlainText(string text)

Converts HTML to plain text by removing tags and special symbols.

Example
string html = "<p>This is <b>HTML</b>.</p>";
string result = TextHelper.ToPlainText(html);
Console.WriteLine(result); // Output: "This is HTML."

ToPlainText(string text, bool preserveLineBreaks)

Converts HTML to plain text, preserving line breaks if specified.

Example
string html = "<p>This is a line.<br/>Another line.</p>";
string result = TextHelper.ToPlainText(html, true);
Console.WriteLine(result); // Output: "This is a line.<br />Another line."

GetKeywords(string text, int count)

Extracts the top unique keywords from the text, ordered by frequency.

Example
string text = "This is a sample text. Sample text is important.";
string keywords = TextHelper.GetKeywords(text, 3);
Console.WriteLine(keywords); // Output: "sample, text, important"

CutText(string text, int maxLength = 200)

Cuts the text to the specified length, attempting to preserve logical blocks by stopping at the nearest sentence-ending dot.

Example
string text = "This is a long text. It has multiple sentences.";
string result = TextHelper.CutText(text, 20);
Console.WriteLine(result); // Output: "This is a long text."

TrimLineBreaksFromStart(string text, string lineBreakPlaceholder)

Removes line break placeholders from the beginning of the text.

Example
string text = "[[LINE_BREAK]][[LINE_BREAK]]Hello!";
string result = TextHelper.TrimLineBreaksFromStart(text);
Console.WriteLine(result); // Output: "Hello!"

Contributing

Contributions to the X.Extensions.Text library are welcome. Please ensure to follow the contributing guidelines specified in the repository for submitting issues, feature requests, or pull requests.

License

The X.Extensions.Text library is released under MIT license.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.3.2 80 11/26/2024
3.3.1 421 8/22/2024
3.3.0 249 7/22/2024