String Extensions
Extensions to numeric data types such as: int, double, decimal, byte...
IsInt
Determines whether the given string is Integer.
bool IsInt(this string source);
Example:bool result = "2".IsInt(); // true bool result = "Hello".IsInt(); // false
IsDouble
Determines whether the given string is Double.
bool IsDouble(this string source);
Example:bool result = "4.78".IsDouble(); // true bool result = "Hello".IsDouble(); // false
IsDecimal
Determines whether the given string is Decimal.
bool IsDecimal(this string source);
Example:bool result = "1.0M".IsDecimal(); // true bool result = "Hello".IsDecimal(); // false
IsDate
Determines whether the given string is Date.
bool IsDate(this string source);
Example:bool result = "01/09/2021".IsDate(); // true bool result = "Hello".IsDate(); // false
IsBoolean
Determines whether the given string is Boolean.
bool IsBoolean(this string source);
Example:bool result = "true".IsBoolean(); // true bool result = "Hello".IsBoolean(); // false
ToBoolean
Converts string type (True | False) to boolean.
bool ToBoolean(this string source);
Example:bool result = "True".ToBoolean(); // true bool result = "false".ToBoolean(); // false
GetInBetween
Determines whether the given string is Date.
Credits: https://stackoverflow.com/a/28723216/12352466
string GetInBetween(this string source, string start, string end);
Example:string text = "This Is FluentExtensions"; string result = text.GetInBetween("This", "FluentExtensions"); // " Is "
ToTitleCase
Converts given text into title case text.
string ToTitleCase(this string source);
Example:string result = "net".ToTitleCase(); // Net string result = "hello".ToTitleCase(); // Hello
ToTitleCase
Converts given text into title case text.
string ToTitleCase(this string source, CultureInfo culture);
Example:CultureInfo culture = new CultureInfo("en-US"); string result = "hello".ToTitleCase(culture); // Hello
IsContainDigits
Determines whether the given string contains digit(s).
bool IsContainDigits(this string source);
Example:bool result = "212 Street".IsContainDigits(); // true bool result = "hello".IsContainDigits(); // false
IsContainLetters
Determines whether the given string contains letter(s).
bool IsContainLetters(this string source);
Example:bool result = "212 Street".IsContainLetters(); // true bool result = "53".IsContainLetters(); // false
AreAllDigits
Determines whether all characters of the given text are digits.
bool AreAllDigits(this string source);
Example:bool result = "212 Street".AreAllDigits(); // false bool result = "53".AreAllDigits(); // true
AreAllLetters
Determines whether all characters of the given text are letters.
bool AreAllLetters(this string source);
Example:bool result = "212 Street".AreAllLetters(); // false bool result = "Hello".AreAllLetters(); // true
FromBase64ToByteArray
Converts back base64 string to byte array.
byte[] FromBase64ToByteArray(this string source);
Example:byte[] result = "SGVsbG8gRnJvbSBGbHVlbnRFeHRlbnNpb25z".FromBase64ToByteArray();
GetBytes
Converts string to byte array.
byte[] GetBytes(this string source);
Example:byte[] result = "Hello World!".GetBytes();
GetBytes
Converts string to byte array.
byte[] GetBytes(this string source, EncodingType encodingType);
Example:byte[] result = "Hello World!".GetBytes(EncodingType.Unicode);
IsEmpty
Determines whether the given text is null or whitespace or empty.
bool IsEmpty(this string source);
Example:bool result = "Hello".IsEmpty(); // false bool result = " ".IsEmpty(); // true bool result = "".IsEmpty(); // true
GetFileExtension
Gets the extension of the file.
string GetFileExtension(this string filePath);
Example:string result = "C:\\file.txt".GetFileExtension();
FileExists
Determines whether the file exists.
bool FileExists(this string filePath);
Example:bool result = "C:\\file.txt".FileExists();
ToFileInDisk
Create a text file based on the given text.
void ToFileInDisk(this string source, string path);
Example:"Hello World!".ToFileInDisk("C:\\file.txt");
ToFileInDiskAsync
Create a text file asynchronously based on the given text.
Task ToFileInDiskAsync(this string source, string path);
Example:await "Hello World!".ToFileInDiskAsync("C:\\file.txt");
ReadFromDisk
Gets the content of the text file.
string ReadFromDisk(this string path);
Example:string result = "C:\\file.txt".ReadFromDisk();
ReadFromDiskAsync
Gets the content of the text file asynchronously.
Task
Example:ReadFromDiskAsync(this string path); string result = await "C:\\file.txt".ReadFromDiskAsync();
AddToEnd
Adds text to end of another text.
string AddToEnd(this string text, string textToAdd, bool addSpaceBeforeAddition = true);
Example:string result = "Hello".AddToEnd("World!"); // Hello World! string result = "Hello".AddToEnd("World!", false); // HelloWorld!
AddToStart
Adds text to start of another text.
string AddToStart(this string text, string textToAdd, bool addSpaceBeforeAddition = true);
Example:string result = "World!".AddToStart("Hello"); // Hello World! string result = "World!".AddToStart("Hello", false); // HelloWorld!
Take
Gets portion of string based on given characters and position to get.
string Take(this string source, int characters, Position from = Position.Start);
Example:string result = "Hello From FluentExtensions".Take(16, Position.End); // FluentExtensions string result = "Hello From FluentExtensions".Take(5); // Hello
ReplaceMultipleWithOne
Gets portion of string based on given characters and position to get.
string ReplaceMultipleWithOne(this string source, string[] values, string value);
Example:string result = "Hello,From.FluentExtensions".ReplaceMultipleWithOne(new string[] {",", "."}, " "); // Hello From FluentExtensions
DriveFreeSpace
Gets the free space of the given drive in gigabytes.
static string DriveFreeSpace(this string driveLetter);
Example:double result = "C".DriveFreeSpace();
DriveTotalSize
Gets the total size of the given drive in gigabytes.
static string DriveTotalSize(this string driveLetter);
Example:double result = "C".DriveTotalSize();
DriveFormat
Gets the format of the given drive.
static string DriveFormat(this string driveLetter);
Example:string result = "C".DriveFormat();
DriveType
Gets the type of the given drive.
static DriveType DriveType(this string driveLetter);
Example:DriveType result = "C".DriveType();
DeleteFile
Delete the given file from disk.
static void DeleteFile(this string filePath);
Example:"C:\\file.txt".DeleteFile();
HideFile
Hides the given file from disk.
static void HideFile(this string filePath);
Example:"C:\\file.txt".HideFile();
ShowFile
Shows the given file from disk (if it's already hidden).
static void ShowFile(this string filePath);
Example:"C:\\file.txt".ShowFile();
CreatedDate
Gets the date and time when this given file created.
static void CreatedDate(this string filePath);
Example:DateTime result = "C:\\file.txt".CreatedDate();
CopyFile
Copies the file to the given destination (overwrites it if it's already exist).
static void CopyFile(this string filePath, string destination);
Example:"C:\\file.txt".CopyFile("D:\\file.txt");
MoveFile
Moves the file to the given destination (overwrites it if it's already exist).
static void MoveFile(this string filePath, string destination);
Example:"C:\\file.txt".MoveFile("D:\\file.txt");
FileSizeInKB
Gets the file size in kilobytes.
static double FileSizeInKB(this string filePath)
Example:double result = "C:\\file.txt".FileSizeInKB();
FileSizeInMB
Gets the file size in megabytes.
static double FileSizeInMB(this string filePath)
Example:double result = "C:\\file.txt".FileSizeInMB();
ReadBytesFromDisk
Reads the file content as array of bytes.
byte[] ReadBytesFromDisk(this string filePath);
Example:byte[] result = "C:\\file.exe".ReadFromDisk();
ReadBytesFromDiskAsync
Reads the file content as array of bytes asynchronously.
Task
Example:ReadBytesFromDiskAsync(this string filePath); byte[] result = await "C:\\file.exe".ReadBytesFromDiskAsync();