• Home
  • Articles
  • API Documentation
Search Results for

    Show / Hide Table of Contents
    • ToSic.Razor.Blade
      • IHtmlTag
      • IHtmlTagsService
      • IScrub
      • Tag
      • Tags
      • Text
    • ToSic.Razor.Html5
      • A
      • Abbr
      • Address
      • Area
      • Article
      • Aside
      • Audio
      • B
      • Base
      • Bdi
      • Bdo
      • Blockquote
      • Br
      • Button
      • Canvas
      • Caption
      • Cite
      • Code
      • Col
      • Colgroup
      • Comment
      • Data
      • Datalist
      • Dd
      • Del
      • Details
      • Dfn
      • Dialog
      • Div
      • Dl
      • Dt
      • Em
      • Embed
      • Fieldset
      • Figcaption
      • Figure
      • Footer
      • Form
      • H1
      • H2
      • H3
      • H4
      • H5
      • H6
      • Head
      • Header
      • Hr
      • I
      • Icon
      • Iframe
      • Img
      • Input
      • Ins
      • Kbd
      • Label
      • Legend
      • Li
      • Link
      • Main
      • Map
      • Mark
      • Meta
      • MetaOg
      • Meter
      • Nav
      • Noscript
      • Object
      • Ol
      • Optgroup
      • Option
      • Output
      • P
      • Param
      • Picture
      • Pre
      • Progress
      • Q
      • Rp
      • Rt
      • Ruby
      • S
      • Samp
      • Script
      • ScriptJsonLd
      • Section
      • Select
      • Small
      • Source
      • Span
      • Strong
      • Style
      • Sub
      • Summary
      • Sup
      • Svg
      • Table
      • Tbody
      • Td
      • Template
      • Textarea
      • Tfoot
      • Th
      • Thead
      • Time
      • Tr
      • Track
      • U
      • Ul
      • Var
      • Video
      • Wbr
    • ToSic.Razor.Markup
      • Attribute
      • AttributeOptions
      • Attributes
      • ITag
      • Tag<T>
      • TagBase
      • TagChildren
      • TagCustom
      • TagList
      • TagOptions
      • TagText
    • ToSic.Razor.StartUp
      • StartUp

    Class Text

    Many simple commands to work with Text / Strings

    Inheritance
    System.Object
    Text
    Namespace: ToSic.Razor.Blade
    Assembly: ToSic.Razor.dll
    Syntax
    public static class Text

    Methods

    | Improve this Doc View Source

    After(String, String, Boolean)

    Get string value after the (first occurrence) key. Case insensitive by default. Will return null in various cases which don't make sense or if not found. Very safe and robust, fully tested.

    Declaration
    public static string After(this string value, string key, bool caseSensitive = false)
    Parameters
    Type Name Description
    System.String value

    The initial string. If null, will always return null

    System.String key

    The key to find. If null, will always return null

    System.Boolean caseSensitive

    Set to true if you need case-sensitive compare

    Returns
    Type Description
    System.String
    Remarks

    New in v3.09

    | Improve this Doc View Source

    AfterLast(String, String, Boolean)

    Get string value after the last occurrence of a key. Will return null in various cases which don't make sense or if not found. Case insensitive by default. Very safe and robust, fully tested.

    Declaration
    public static string AfterLast(this string value, string key, bool caseSensitive = false)
    Parameters
    Type Name Description
    System.String value

    The initial string. If null, will always return null

    System.String key

    The key to find. If null, will always return null

    System.Boolean caseSensitive

    Set to true if you need case-sensitive compare

    Returns
    Type Description
    System.String
    Remarks

    New in v3.09

    | Improve this Doc View Source

    Before(String, String, Boolean)

    Get string value before the key. Case insensitive by default. Will return null in various cases which don't make sense or if not found. Very safe and robust, fully tested.

    Declaration
    public static string Before(this string value, string key, bool caseSensitive = false)
    Parameters
    Type Name Description
    System.String value

    The initial string. If null, will always return null

    System.String key

    The key to find. If null, will always return null

    System.Boolean caseSensitive

    Set to true if you need case-sensitive compare

    Returns
    Type Description
    System.String
    Remarks

    New in v3.09

    | Improve this Doc View Source

    BeforeLast(String, String, Boolean)

    Get string value before the last occurrence of a key. Case insensitive by default. Will return null in various cases which don't make sense or if not found. Very safe and robust, fully tested.

    Declaration
    public static string BeforeLast(this string value, string key, bool caseSensitive = false)
    Parameters
    Type Name Description
    System.String value

    The initial string. If null, will always return null

    System.String key

    The key to find. If null, will always return null

    System.Boolean caseSensitive

    Set to true if you need case-sensitive compare

    Returns
    Type Description
    System.String
    Remarks

    New in v3.09

    | Improve this Doc View Source

    Between(String, String, String, Boolean, Boolean)

    Get the text between two keys

    Declaration
    public static string Between(this string value, string before, string after, bool goToEndIfEndNotFound = false, bool caseSensitive = false)
    Parameters
    Type Name Description
    System.String value

    The initial string. If null, will always return null

    System.String before

    The key to find in front of what we're looking for. If null, will always return null

    System.String after

    The key to find in front of what we're looking for. If null, will always return null

    System.Boolean goToEndIfEndNotFound

    If true and the end isn't found, it will return the rest of the string

    System.Boolean caseSensitive

    Set to true if you need case-sensitive compare

    Returns
    Type Description
    System.String
    Remarks

    New in v3.09

    | Improve this Doc View Source

    Crop(String, Int32)

    Cut off a text at the best possible place with a max-length. This will count html-entities like &, &nbsp; or umlauts as 1 character, and will try to cut off between words if possible. So it will backtrack to the previous space.

    Declaration
    public static string Crop(this string value, int length)
    Parameters
    Type Name Description
    System.String value

    String to cut off. Can contain umlauts and html-entities, but should not contain html-tags as there are not treated properly.

    System.Int32 length

    length to cut off at

    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    Ellipsis(String, Int32, String)

    Crop a text if too long, add in that case, also add an ellipsis &hellip; or a custom suffix (optional)

    Declaration
    public static string Ellipsis(this string value, int length, string suffix = null)
    Parameters
    Type Name Description
    System.String value

    Value to maybe truncate (using safe-truncate - see Text.Crop)

    System.Int32 length

    Max length to keep

    System.String suffix

    optional suffix, defaults to &hellip;

    Returns
    Type Description
    System.String
    Remarks

    If you don't need the suffix, use CropText(...) instead

    | Improve this Doc View Source

    First(Boolean, String[])

    Try to return the first possible value, but if it's empty, return null

    Declaration
    public static string First(bool handleHtmlWhitespaces = true, params string[] values)
    Parameters
    Type Name Description
    System.Boolean handleHtmlWhitespaces

    if true (default) will treat html-whitespace as a space

    System.String[] values

    array of values to check consecutively

    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    First(String[])

    Try to return the first possible value, but if it's empty, return null

    Declaration
    public static string First(params string[] values)
    Parameters
    Type Name Description
    System.String[] values

    array of values to check consecutively

    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    Has(Object, Boolean)

    Returns true if it has real text, false if it's null, not a string, an empty string or a string containing just whitespace and/or html-whitespaces like &amp;nbsp; or &amp;#160;

    Declaration
    public static bool Has(object value, bool handleHtmlWhitespaces = true)
    Parameters
    Type Name Description
    System.Object value
    System.Boolean handleHtmlWhitespaces

    if true (default) will treat html-whitespace as a space

    Returns
    Type Description
    System.Boolean

    true, if it's a string with real content

    Remarks

    will try to cast the object as string first, so it will be null if not a real string

    | Improve this Doc View Source

    Has(String, Boolean)

    Will check if a string actually has contents (not null, empty or just spaces)

    Declaration
    public static bool Has(this string value, bool handleHtmlWhitespaces = true)
    Parameters
    Type Name Description
    System.String value
    System.Boolean handleHtmlWhitespaces

    if true (default) will treat html-whitespace as a space

    Returns
    Type Description
    System.Boolean

    true, if the string has real contents

    | Improve this Doc View Source

    Zip(String)

    Will remove all new-lines from a string and merge multiple spaces together.

    Declaration
    public static string Zip(this string value)
    Parameters
    Type Name Description
    System.String value
    Returns
    Type Description
    System.String
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX