Show / Hide Table of Contents

Class StringExtensions

Represents various extension methods for type String.

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: DotNext
Assembly: DotNext.dll
Syntax
public static class StringExtensions

Methods

| Improve this Doc View Source

AsTemplate(String, Char)

Compiles string template.

Declaration
public static MemoryTemplate<char> AsTemplate(this string template, char placeholder)
Parameters
Type Name Description
String template

The string representing template with placeholders.

Char placeholder

The placeholder in the template.

Returns
Type Description
MemoryTemplate<Char>

The compiled template that can be used to replace all placeholders with their original values.

| Improve this Doc View Source

AsTemplate(String, String)

Compiles string template.

Declaration
public static MemoryTemplate<char> AsTemplate(this string template, string placeholder)
Parameters
Type Name Description
String template

The string representing template with placeholders.

String placeholder

The placeholder in the template.

Returns
Type Description
MemoryTemplate<Char>

The compiled template that can be used to replace all placeholders with their original values.

| Improve this Doc View Source

GetRawData(String)

Gets managed pointer to the first character in the string.

Declaration
[Obsolete("Use String.GetPinnableReference method instead")]
public static char GetRawData(string str)
Parameters
Type Name Description
String str

The string data.

Returns
Type Description
Char

The managed pointer to the first character in the string.

| Improve this Doc View Source

IfNullOrEmpty(String, String)

Returns alternative string if first string argument is null or empty.

Declaration
public static string IfNullOrEmpty(this string str, string alt)
Parameters
Type Name Description
String str

A string to check.

String alt

Alternative string to be returned if original string is null or empty.

Returns
Type Description
String

Original or alternative string.

Examples

This method is equivalent to the following code:

var result = string.IsNullOrEmpty(str) ? alt : str;
| Improve this Doc View Source

IsEqualIgnoreCase(String, String)

Compares two string using OrdinalIgnoreCase.

Declaration
[Obsolete("Use string.Equals(string, string, StringComparison) static method instead")]
public static bool IsEqualIgnoreCase(this string strA, string strB)
Parameters
Type Name Description
String strA

String A. Can be null.

String strB

String B. Can be null.

Returns
Type Description
Boolean

true, if the first string is equal to the second string; otherwise, false.

| Improve this Doc View Source

Reverse(String)

Reverse string characters.

Declaration
public static string Reverse(this string str)
Parameters
Type Name Description
String str

The string to reverse.

Returns
Type Description
String

The string in inverse order of characters.

| Improve this Doc View Source

Split(String, Int32)

Split a string into several substrings, each has a length not greater the specified one.

Declaration
[Obsolete("Use ReadOnlyMemory<T>.Slice instead", true)]
public static ChunkSequence<char> Split(string str, int chunkSize)
Parameters
Type Name Description
String str

The string to split.

Int32 chunkSize

The maximum length of the substring in the sequence.

Returns
Type Description
ChunkSequence<Char>

The sequence of substrings.

| Improve this Doc View Source

Substring(String, Range)

Extracts substring from the given string.

Declaration
public static string Substring(this string str, Range range)
Parameters
Type Name Description
String str

The instance of string.

Range range

The range of substring.

Returns
Type Description
String

The part of str extracted according with supplied range.

Remarks

This method if useful for .NET languages without syntactic support of ranges.

| Improve this Doc View Source

TrimLength(String, Int32)

Trims the source string to specified length if it exceeds it. If source string is less that maxLength then the source string returned.

Declaration
public static string TrimLength(this string str, int maxLength)
Parameters
Type Name Description
String str

Source string.

Int32 maxLength

Maximum length.

Returns
Type Description
String

Trimmed string value.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX