• Articles
  • API Documentation
  • GitHub
  • Abhith
  • API Documentation
  • Code.Library.Extensions
  • StringExtensions

    Show / Hide Table of Contents
    • Code.Library
      • Breadcrumb
      • BreadcrumbNode
      • IAuditedObject
      • IAuditedObject<TUser>
      • ICreationAuditedObject
      • ICreationAuditedObject<TCreator>
      • IDeletionAuditedObject
      • IDeletionAuditedObject<TUser>
      • IHasCreationTime
      • IHasDeletionTime
      • IHasModificationTime
      • IMayHaveCreator
      • IMayHaveCreator<TCreator>
      • IModificationAuditedObject
      • IModificationAuditedObject<TUser>
      • IResult
      • ISoftDelete
      • Result
      • Result<T>
      • Result<T, E>
      • ResultFailureException
      • ResultFailureException<E>
      • ResultSuccessException
    • Code.Library.Application.Behaviors
      • LoggingBehavior<TRequest, TResponse>
      • RequestPerformanceBehavior<TRequest, TResponse>
      • UnhandledExceptionBehavior<TRequest, TResponse>
    • Code.Library.AspNetCore
      • PerfTracker
      • ServiceCollectionExtensions
    • Code.Library.AspNetCore.Attributes
      • LogUsageAttribute
    • Code.Library.AspNetCore.Extensions
      • HealthCheckEndpointRouteBuilderExtensions
      • HttpRequestExtensions
      • ILoggerExtensions
    • Code.Library.AspNetCore.Filters
      • TrackPerformanceFilter
    • Code.Library.AspNetCore.Helpers
      • SerilogHelper
    • Code.Library.AspNetCore.Middleware
      • ApiExceptionMiddleware
      • ApiExceptionMiddlewareExtensions
      • ApiExceptionOptions
      • RequestLoggingMiddlewareExtensions
    • Code.Library.AspNetCore.Middleware.RequestResponseLogging
      • ExcludeInRequestResponseLoggingOptions
      • IncludeInRequestResponseLoggingOptions
      • RequestResponseLoggingMiddleware
      • RequestResponseLoggingMiddlewareExtensions
      • RequestResponseLoggingOptions
    • Code.Library.Domain.Models
      • Enumeration
    • Code.Library.Dtos
      • AuditedEntityDto
      • AuditedEntityDto<TPrimaryKey>
      • CreationAuditedEntityDto
      • CreationAuditedEntityDto<TPrimaryKey>
      • EntityDto
      • EntityDto<TKey>
      • EntityRequestDto<TKey>
      • FullAuditedEntityDto
      • FullAuditedEntityDto<TPrimaryKey>
      • IEntityDto
      • IEntityDto<TKey>
      • IFullAuditedObject
      • IFullAuditedObject<TUser>
      • IHasTotalCount
      • ILimitedResultRequest
      • IListResult<T>
      • IPagedAndSortedResultRequest
      • IPagedResult<T>
      • IPagedResultRequest
      • ISortedResultRequest
      • LimitedResultRequestDto
      • ListResultDto<T>
      • PagedAndSortedResultRequestDto
      • PagedResultDto<T>
      • PagedResultRequestDto
    • Code.Library.Exceptions
      • DomainException
    • Code.Library.Extensions
      • DateTimeExtensions
      • FileSystemExtensions
      • GenericTypeExtensions
      • IEnumerableExtensions
      • NumberExtensions
      • ResultExtensions
      • StringExtensions
    • Code.Library.Helpers
      • DateTimeHelper
      • FileHelper
      • SerializationHelper
      • ThirdPartyHelper

    Class StringExtensions

    All String extensions.

    Inheritance
    object
    StringExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Code.Library.Extensions
    Assembly: Code.Library.dll
    Syntax
    public static class StringExtensions

    Methods

    | Improve this Doc View Source

    Clean(string, bool)

    Clean the content by replacing special characters/HTML tags.

    Declaration
    public static string Clean(this string content, bool removeHtml = true)
    Parameters
    Type Name Description
    string content

    The content.

    bool removeHtml

    The remove html.

    Returns
    Type Description
    string

    The string.

    | Improve this Doc View Source

    CleanForXss(string, params char[])

    Cleans string to aid in preventing xss attacks.

    Declaration
    public static string CleanForXss(this string input, params char[] ignoreFromClean)
    Parameters
    Type Name Description
    string input

    Input string.

    char[] ignoreFromClean

    Characters to ignore during clean.

    Returns
    Type Description
    string

    Cleaned string.

    | Improve this Doc View Source

    EnsureEndsWith(string, char)

    All String extensions.

    Declaration
    public static string EnsureEndsWith(this string input, char value)
    Parameters
    Type Name Description
    string input
    char value
    Returns
    Type Description
    string
    | Improve this Doc View Source

    EnsureEndsWith(string, string)

    All String extensions.

    Declaration
    public static string EnsureEndsWith(this string input, string toEndWith)
    Parameters
    Type Name Description
    string input
    string toEndWith
    Returns
    Type Description
    string
    | Improve this Doc View Source

    EnsureStartsWith(string, char)

    All String extensions.

    Declaration
    public static string EnsureStartsWith(this string input, char value)
    Parameters
    Type Name Description
    string input
    char value
    Returns
    Type Description
    string
    | Improve this Doc View Source

    ExceptChars(string, HashSet<char>)

    All String extensions.

    Declaration
    public static string ExceptChars(this string str, HashSet<char> toExclude)
    Parameters
    Type Name Description
    string str
    HashSet<char> toExclude
    Returns
    Type Description
    string
    | Improve this Doc View Source

    GetLast(string, int)

    Get last N characters from a string

    Declaration
    public static string GetLast(this string source, int numberOfChars)
    Parameters
    Type Name Description
    string source
    int numberOfChars
    Returns
    Type Description
    string
    | Improve this Doc View Source

    IfNullOrWhiteSpace(string, string)

    Returns default value if string is null or whitespace.

    Declaration
    public static string IfNullOrWhiteSpace(this string str, string defaultValue)
    Parameters
    Type Name Description
    string str

    Input string.

    string defaultValue

    Default value.

    Returns
    Type Description
    string

    Returns default value if string is null or whitespace else return the string itself.

    | Improve this Doc View Source

    IsLowerCase(char)

    All String extensions.

    Declaration
    public static bool IsLowerCase(this char ch)
    Parameters
    Type Name Description
    char ch
    Returns
    Type Description
    bool
    | Improve this Doc View Source

    IsNumber(string, bool)

    true, if the string can be parsed as Double respective Int32 Spaces are not considred.

    Declaration
    public static bool IsNumber(this string s, bool floatpoint)
    Parameters
    Type Name Description
    string s

    input string

    bool floatpoint

    true, if Double is considered, otherwhise Int32 is considered.

    Returns
    Type Description
    bool

    true, if the string contains only digits or float-point

    | Improve this Doc View Source

    IsNumberOnly(string, bool)

    true, if float-point is considered

    Declaration
    public static bool IsNumberOnly(this string s, bool floatpoint)
    Parameters
    Type Name Description
    string s
    bool floatpoint
    Returns
    Type Description
    bool

    true, if the string contains only digits or float-point

    | Improve this Doc View Source

    IsRtl(string)

    To check whether the given string is Arabic.

    Declaration
    public static bool IsRtl(this string input)
    Parameters
    Type Name Description
    string input
    Returns
    Type Description
    bool

    Returns True if Arabic

    | Improve this Doc View Source

    IsUpperCase(char)

    All String extensions.

    Declaration
    public static bool IsUpperCase(this char ch)
    Parameters
    Type Name Description
    char ch
    Returns
    Type Description
    bool
    | Improve this Doc View Source

    IsValidEmailAddress(string)

    To check whether the string is a valid email.

    Declaration
    public static bool IsValidEmailAddress(this string email)
    Parameters
    Type Name Description
    string email
    Returns
    Type Description
    bool
    | Improve this Doc View Source

    IsValidUrl(string)

    Validate if the given string is URL or not.

    Declaration
    public static bool IsValidUrl(this string url)
    Parameters
    Type Name Description
    string url

    URL.

    Returns
    Type Description
    bool

    True or False.

    | Improve this Doc View Source

    MD5(string)

    generates MD5.

    Declaration
    public static string MD5(this string s)
    Parameters
    Type Name Description
    string s
    Returns
    Type Description
    string
    | Improve this Doc View Source

    Mask(string, int, string)

    Mask the string.

    Declaration
    public static string Mask(this string value, int startIndex, string mask)
    Parameters
    Type Name Description
    string value

    String that need to be masked

    int startIndex

    zero index indicating mask start position

    string mask

    mask that need to be applied, eg. ***

    Returns
    Type Description
    string

    Usage: "123456789".Mask(3, "") => "12389"

    | Improve this Doc View Source

    Nl2Br(string)

    Replace \r\n or \n by

    Declaration
    public static string Nl2Br(this string s)
    Parameters
    Type Name Description
    string s
    Returns
    Type Description
    string
    | Improve this Doc View Source

    OrIfNullOrWhiteSpace(string, string)

    All String extensions.

    Declaration
    public static string OrIfNullOrWhiteSpace(this string input, string alternative)
    Parameters
    Type Name Description
    string input
    string alternative
    Returns
    Type Description
    string
    | Improve this Doc View Source

    RemoveDiacritics(string)

    All String extensions.

    Declaration
    public static string RemoveDiacritics(this string s)
    Parameters
    Type Name Description
    string s
    Returns
    Type Description
    string
    | Improve this Doc View Source

    RemoveSpaces(string)

    remove white space, not line end. Useful when parsing user input such phone, price int.Parse("1 000 000".RemoveSpaces(),.....

    Declaration
    public static string RemoveSpaces(this string s)
    Parameters
    Type Name Description
    string s
    Returns
    Type Description
    string
    | Improve this Doc View Source

    ReplaceLastOccurrence(string, string, string)

    Replace last occurance in a string

    Declaration
    public static string ReplaceLastOccurrence(this string source, string find, string replace)
    Parameters
    Type Name Description
    string source
    string find
    string replace
    Returns
    Type Description
    string
    | Improve this Doc View Source

    Reverse(string)

    Reverse the string.

    Declaration
    public static string Reverse(this string input)
    Parameters
    Type Name Description
    string input
    Returns
    Type Description
    string
    | Improve this Doc View Source

    SanitizeURL(string)

    returns "safe" URL, stripping anything outside normal charsets for URL

    Declaration
    public static string SanitizeURL(this string url)
    Parameters
    Type Name Description
    string url

    Input URL string.

    Returns
    Type Description
    string

    Safe URL.

    | Improve this Doc View Source

    StripHtml(string)

    Strips all html from a string.

    Declaration
    public static string StripHtml(this string text)
    Parameters
    Type Name Description
    string text

    The text.

    Returns
    Type Description
    string

    Returns the string without any html tags.

    | Improve this Doc View Source

    ToFirstLower(string)

    Returns a copy of the string with the first character converted to lowercase.

    Declaration
    public static string ToFirstLower(this string input)
    Parameters
    Type Name Description
    string input

    The string.

    Returns
    Type Description
    string

    The converted string.

    | Improve this Doc View Source

    ToFirstLower(string, CultureInfo)

    Returns a copy of the string with the first character converted to lowercase using the casing rules of the specified culture.

    Declaration
    public static string ToFirstLower(this string input, CultureInfo culture)
    Parameters
    Type Name Description
    string input

    The string.

    CultureInfo culture

    The culture.

    Returns
    Type Description
    string

    The converted string.

    | Improve this Doc View Source

    ToFirstLowerInvariant(string)

    Returns a copy of the string with the first character converted to lowercase using the casing rules of the invariant culture.

    Declaration
    public static string ToFirstLowerInvariant(this string input)
    Parameters
    Type Name Description
    string input

    The string.

    Returns
    Type Description
    string

    The converted string.

    | Improve this Doc View Source

    ToFirstUpper(string)

    Returns a copy of the string with the first character converted to uppercase.

    Declaration
    public static string ToFirstUpper(this string input)
    Parameters
    Type Name Description
    string input

    The string.

    Returns
    Type Description
    string

    The converted string.

    | Improve this Doc View Source

    ToFirstUpper(string, CultureInfo)

    Returns a copy of the string with the first character converted to uppercase using the casing rules of the specified culture.

    Declaration
    public static string ToFirstUpper(this string input, CultureInfo culture)
    Parameters
    Type Name Description
    string input

    The string.

    CultureInfo culture

    The culture.

    Returns
    Type Description
    string

    The converted string.

    | Improve this Doc View Source

    ToFirstUpperInvariant(string)

    Returns a copy of the string with the first character converted to uppercase using the casing rules of the invariant culture.

    Declaration
    public static string ToFirstUpperInvariant(this string input)
    Parameters
    Type Name Description
    string input

    The string.

    Returns
    Type Description
    string

    The converted string.

    | Improve this Doc View Source

    ToFriendlyUrl(string)

    The get friendly url.

    Declaration
    public static string ToFriendlyUrl(this string title)
    Parameters
    Type Name Description
    string title

    The title.

    Returns
    Type Description
    string

    The string.

    | Improve this Doc View Source

    ToNullableBool(string)

    string to nullable bool.

    Declaration
    public static bool? ToNullableBool(this string s)
    Parameters
    Type Name Description
    string s

    Input string.

    Returns
    Type Description
    bool?

    Null or bool.

    | Improve this Doc View Source

    ToNullableInt32(string)

    string to nullable int.

    Declaration
    public static int? ToNullableInt32(this string s)
    Parameters
    Type Name Description
    string s

    string.

    Returns
    Type Description
    int?

    integer or null.

    | Improve this Doc View Source

    TruncateAtWord(string, int, bool)

    Truncate string at a word near to the limit specified. Avoid word split.

    Declaration
    public static string TruncateAtWord(this string input, int length, bool appendDots = false)
    Parameters
    Type Name Description
    string input

    string

    int length
    bool appendDots
    Returns
    Type Description
    string
    | Improve this Doc View Source

    UppercaseWords(string)

    Uppercase words. This program defines a method named UppercaseWords that is equivalent to the ucwords function in scripting languages such as PHP. The UppercaseWords method internally converts the string to a character array buffer.

    Declaration
    public static string UppercaseWords(string value)
    Parameters
    Type Name Description
    string value
    Returns
    Type Description
    string
    | Improve this Doc View Source

    UrlAvailable(string)

    Checks if URL is valid.

    Declaration
    public static bool UrlAvailable(this string httpUrl)
    Parameters
    Type Name Description
    string httpUrl
    Returns
    Type Description
    bool

    true if available.

    Examples

    string url = "www.codeproject.com; if( !url.UrlAvailable()) ...codeproject is not available.

    • Improve this Doc
    • View Source
    In This Article
    • Methods
      • Clean(string, bool)
      • CleanForXss(string, params char[])
      • EnsureEndsWith(string, char)
      • EnsureEndsWith(string, string)
      • EnsureStartsWith(string, char)
      • ExceptChars(string, HashSet<char>)
      • GetLast(string, int)
      • IfNullOrWhiteSpace(string, string)
      • IsLowerCase(char)
      • IsNumber(string, bool)
      • IsNumberOnly(string, bool)
      • IsRtl(string)
      • IsUpperCase(char)
      • IsValidEmailAddress(string)
      • IsValidUrl(string)
      • MD5(string)
      • Mask(string, int, string)
      • Nl2Br(string)
      • OrIfNullOrWhiteSpace(string, string)
      • RemoveDiacritics(string)
      • RemoveSpaces(string)
      • ReplaceLastOccurrence(string, string, string)
      • Reverse(string)
      • SanitizeURL(string)
      • StripHtml(string)
      • ToFirstLower(string)
      • ToFirstLower(string, CultureInfo)
      • ToFirstLowerInvariant(string)
      • ToFirstUpper(string)
      • ToFirstUpper(string, CultureInfo)
      • ToFirstUpperInvariant(string)
      • ToFriendlyUrl(string)
      • ToNullableBool(string)
      • ToNullableInt32(string)
      • TruncateAtWord(string, int, bool)
      • UppercaseWords(string)
      • UrlAvailable(string)
    Back to top Generated by Abhith Rajan using DocFX