Skip to content

The most used string algorithms gathered under a single class

Notifications You must be signed in to change notification settings

meto260/MyStringExtensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My String Extensions

The most used string algorithms gathered under a single class

Install

NuGet\Install-Package MyStringExtensions -Version 2.0.0

version of package for use last version see https://www.nuget.org/packages/MyStringExtensions/

How to use

Cut(length) Substring for unknown length. No errors for mismatches due to empty space or lengthSubstring for unknown length. No errors for mismatches due to empty space or length

string sourceText = "++a little Bunny raBBit waNdering in a huge Forest";
string nullText = null;

Console.WriteLine(nullText.Cut(22));
//Output: ""

//----------------------------------

Console.WriteLine(sourceText.Cut(5));
//Output: "++a l"

TrimInside() Trim all whitespace in text

Console.WriteLine(sourceText.TrimInside());
//Output: "++alittleBunnyraBBitwaNderinginahugeForest"

NullExists() Check Null or Empty value in string collection

var nulls = new List<string> { "t1", null, "t2" };
Console.WriteLine(nulls.NullExists());
//Output: "True"

//----------------------------------

nulls = new List<string> { "t1", "t2", "t3" };
Console.WriteLine(nulls.NullExists());
//Output: "False"

ContainsNosense(seek) Find a word in string without sensivity

Console.WriteLine(sourceText.ContainsNosense("rabbit"));
//Output: "True"

//----------------------------------

Console.WriteLine(sourceText.ContainsNosense("horse"));
//Output: "False"

CountWords(seek) Find how many times the word you are looking for is repeated in the text

Console.WriteLine(sourceText.CountWords("rabbit"));
//Output: 1

//----------------------------------
Console.WriteLine(sourceText.CountWords("horse"));
//Output: 0

RandomString(length) Generate Random text

Console.WriteLine(StringExtensions.RandomString(12));
//Output: "%0n9jdhwENCv"

EncryptHash() Generate non-recyclable writing from your text

Console.WriteLine(sourceText.EncryptHash());
//Output: "9bbdadb281d35bfd90270a06abe0f12ec061957f38a36d8aceefb95630cac6d1"

Mask(start, length) Generate masked text from your text

Console.WriteLine(sourceText.Mask(8,12));
//Output: "++a littl***********Bit waNdering in a huge Forest"

Mask(startLength, maskLength, endLength, maskChar='*') Generate masked text from your text

Console.WriteLine("HelloWorld!".Mask(4,2, 2, 'x'));
//Helloxxld!

ToImage() Text to image bytes. Exports png file bytes. Only works on Windows OS

var imgBytes = sourceText.ToImage();
File.WriteAllBytes("img.png", imgBytes);
//Output: "img file"

ForWordsIn(seek, act) Run a delegated action for each found word. Detailed

sourceText.ForWordsIn("i", x => Console.WriteLine(x));
//Output:
    //"little
    //"raBBit"
    //"waNdering"
    //"in"

ToTitleCase() Make uppercase the first letters after a space

Console.WriteLine(sourceText.ToTitleCase());
//Output: "++A Little Bunny Rabbit Wandering In A Huge Forest"

ToBodyCase() Make uppercase the first character of the text

Console.WriteLine(sourceText.ToBodyCase());
//Output: "++A little Bunny raBBit waNdering in a huge Forest"

ToLowerUnderscored() Make snakecase for source text

Console.WriteLine(sourceText.ToLowerUnderscored());
//Output: "++a_little_bunny_ra_b_bit_wa_ndering_in_a_huge_forest"

Singularize() Deduplicate characters that repeat side by side

Console.WriteLine(sourceText.Singularize());
//Output: "+a litle Buny raBit waNdering in a huge Forest"

Multiplex(length) Duplicate a selected text as many times as you like

Console.WriteLine("#".Multiplex(21));
//Output: "######################"

LoopIn(func) Run an action for each character in the text

var result = sourceText.LoopIn(x => {
    if (x.Equals('h')) {
        return true;
    }
    return false;
});
Console.WriteLine(result);
//Output: True

ClearDigits() Remove numeric chars and return new string object

Console.WriteLine("123 ankara ++".ClearDigits());
//Output: "ankara ++"

ClearSymbols() Remove symbolic chars and return new string object

Console.WriteLine(sourceText.ClearSymbols());
//Output: "a little Bunny raBBit waNdering in a huge Forest"

ClearDigits() + ClearSymbols() + TrimInside()

Console.WriteLine("123 ankara ++ merkez".ClearDigits().ClearSymbols().TrimInside());
//Output: "ankaramerkez"

Compress() Compress text size

string gg = "Kediler, baðýmsýz ve meraklý yapýlarýyla bilinen evcil hayvanlardýr. Çeþitli boyut ve renklerde olmalarýna raðmen ortak bazý özellikleri vardýr. Okþandýklarýnda mýrýldanmalarý, avlanma içgüdülerinin güçlü olmasý ve yüksek yerlere týrmanmaktan hoþlanmalarý kedilerin dikkat çekici özelliklerindendir. Bazý insanlar kedileri yalnýz ve mesafeli bulurken, diðerleri onlarýn sevgi dolu ve sadýk arkadaþlar olduðunu düþünür. Tarih boyunca insanlarla birlikte yaþayan kediler, hem evlerde hem de sokaklarda yaþamýný sürdürebilirler.";
Console.WriteLine("Compressed Text      : " + gg);
Console.WriteLine();
Console.WriteLine("Compressed Size      : " + gg.Compress().Length);
Console.WriteLine("Decompressed Size    : " + Encoding.ASCII.GetBytes(gg).Length);

//Compressed Text      : Kediler, baðýmsýz ve meraklý yapýlarýyla bilinen evcil hayvanlardýr. Çeþitli boyut ve renklerde olmalarýna raðmen ortak bazý özellikleri vardýr. Okþandýklarýnda mýrýldanmalarý, avlanma içgüdülerinin güçlü olmasý ve yüksek yerlere týrmanmaktan hoþlanmalarý kedilerin dikkat çekici özelliklerindendir. Bazý insanlar kedileri yalnýz ve mesafeli bulurken, diðerleri onlarýn sevgi dolu ve sadýk arkadaþlar olduðunu düþünür. Tarih boyunca insanlarla birlikte yaþayan kediler, hem evlerde hem de sokaklarda yaþamýný sürdürebilirler.
//Compressed Size      : 460
//Decompressed Size    : 525

About

The most used string algorithms gathered under a single class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages