Class StrUtils
Provides core string utility functions used by the majority of projects
Inheritance
System.Object
StrUtils
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Azos
Assembly: Azos.dll
Syntax
public static class StrUtils
Fields
WIN_UNIX_LINE_BRAKES
Declaration
public static readonly string[] WIN_UNIX_LINE_BRAKES
Field Value
| Type |
Description |
| System.String[] |
|
Methods
AppendFormatLine(StringBuilder, String, Object)
Appends the string followed by new line and returned by processing a composite format string, which contains zero or more format items, to this instance.
Each format item is replaced by the string representation of a single argument.
Declaration
public static StringBuilder AppendFormatLine(this StringBuilder builder, string str, object arg0)
Parameters
| Type |
Name |
Description |
| System.Text.StringBuilder |
builder |
|
| System.String |
str |
|
| System.Object |
arg0 |
|
Returns
| Type |
Description |
| System.Text.StringBuilder |
|
AppendFormatLine(StringBuilder, String, Object, Object)
Appends the string followed by new line and returned by processing a composite format string, which contains zero or more format items, to this instance.
Each format item is replaced by the string representation of a single argument.
Declaration
public static StringBuilder AppendFormatLine(this StringBuilder builder, string str, object arg0, object arg1)
Parameters
| Type |
Name |
Description |
| System.Text.StringBuilder |
builder |
|
| System.String |
str |
|
| System.Object |
arg0 |
|
| System.Object |
arg1 |
|
Returns
| Type |
Description |
| System.Text.StringBuilder |
|
AppendFormatLine(StringBuilder, String, Object, Object, Object)
Appends the string followed by new line and returned by processing a composite format string, which contains zero or more format items, to this instance.
Each format item is replaced by the string representation of a single argument.
Declaration
public static StringBuilder AppendFormatLine(this StringBuilder builder, string str, object arg0, object arg1, object arg2)
Parameters
| Type |
Name |
Description |
| System.Text.StringBuilder |
builder |
|
| System.String |
str |
|
| System.Object |
arg0 |
|
| System.Object |
arg1 |
|
| System.Object |
arg2 |
|
Returns
| Type |
Description |
| System.Text.StringBuilder |
|
AppendFormatLine(StringBuilder, String, Object[])
Appends the string followed by new line and returned by processing a composite format string, which contains zero or more format items, to this instance.
Each format item is replaced by the string representation of a single argument.
Declaration
public static StringBuilder AppendFormatLine(this StringBuilder builder, string str, params object[] args)
Parameters
| Type |
Name |
Description |
| System.Text.StringBuilder |
builder |
|
| System.String |
str |
|
| System.Object[] |
args |
|
Returns
| Type |
Description |
| System.Text.StringBuilder |
|
Args(String, Object[])
Shortcut helper for string.Format(tpl, params object[] args)
Declaration
public static string Args(this string tpl, params object[] args)
Parameters
| Type |
Name |
Description |
| System.String |
tpl |
|
| System.Object[] |
args |
|
Returns
| Type |
Description |
| System.String |
|
ArgsTpl(String, Object)
Interprets template of the form: Some text {@value_name@:C} by replacing with property/field values.
Note: this function does not recognize escapes for simplicity (as escapes can be replaced by regular strings instead)
Declaration
public static string ArgsTpl(this string tpl, object args)
Parameters
| Type |
Name |
Description |
| System.String |
tpl |
|
| System.Object |
args |
|
Returns
| Type |
Description |
| System.String |
|
ArgsTpl(String, Object, out Boolean)
Interprets template of the form: Some text {@value_name@:C} by replacing with property/field values.
Note: this function does not recognize escapes for simplicity (as escapes can be replaced by regular strings instead).
Matched is set to true if at least one property match was made
Declaration
public static string ArgsTpl(this string tpl, object args, out bool matched)
Parameters
| Type |
Name |
Description |
| System.String |
tpl |
|
| System.Object |
args |
|
| System.Boolean |
matched |
|
Returns
| Type |
Description |
| System.String |
|
Burmatographize(String, Boolean)
Swaps string letters that "obfuscates" string- useful for generation of keys from strings that have to become non-obvious to user.
This function does not offer any real protection (as it is easy to decipher the original value), just visual.
The name comes from non-existing science "Burmatography" used in "Neznaika" kids books
Declaration
public static string Burmatographize(this string src, bool rtl = false)
Parameters
| Type |
Name |
Description |
| System.String |
src |
|
| System.Boolean |
rtl |
|
Returns
| Type |
Description |
| System.String |
|
CapitalizeFirstChar(String)
Capitalizes first character of string
Declaration
public static string CapitalizeFirstChar(this string str)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
Returns
| Type |
Description |
| System.String |
|
Default(String, String)
Defaults string if it is null or whitespace
Declaration
public static string Default(this string str, string val = "")
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
| System.String |
val |
|
Returns
| Type |
Description |
| System.String |
|
DiffStrings(String, String, Int32)
Creates a string listing char-by char difference between strings
Declaration
public static string DiffStrings(this string a, string b, int limit = 0)
Parameters
| Type |
Name |
Description |
| System.String |
a |
|
| System.String |
b |
|
| System.Int32 |
limit |
|
Returns
| Type |
Description |
| System.String |
|
EqualsIgnoreCase(String, String)
Helper function that performs case-insensitive comparison between strings using invariant comparison.
Either lhs and rhs can be null.
Use this in conjunction with GetHashCodeIgnoreCase
Declaration
public static bool EqualsIgnoreCase(this string lhs, string rhs)
Parameters
| Type |
Name |
Description |
| System.String |
lhs |
|
| System.String |
rhs |
|
Returns
| Type |
Description |
| System.Boolean |
|
EqualsOrdIgnoreCase(String, String)
Helper function that performs case-insensitive comparison between strings using ordinal comparison.
Either lhs and rhs can be null.
Use this in conjunction with GetHashCodeOrdIgnoreCase
Declaration
public static bool EqualsOrdIgnoreCase(this string lhs, string rhs)
Parameters
| Type |
Name |
Description |
| System.String |
lhs |
|
| System.String |
rhs |
|
Returns
| Type |
Description |
| System.Boolean |
|
EqualsOrdSenseCase(String, String)
Helper function that performs case-insensitive comparison between strings using ordinal comparison.
Either lhs and rhs can be null.
Use this in conjunction with GetHashCodeOrdSenseCase
Declaration
public static bool EqualsOrdSenseCase(this string lhs, string rhs)
Parameters
| Type |
Name |
Description |
| System.String |
lhs |
|
| System.String |
rhs |
|
Returns
| Type |
Description |
| System.Boolean |
|
EqualsSenseCase(String, String)
Helper function that performs comparison between strings using invariant comparison.
Either lhs and rhs can be null.
Use this in conjunction with GetHashCodeSenseCase
Declaration
public static bool EqualsSenseCase(this string lhs, string rhs)
Parameters
| Type |
Name |
Description |
| System.String |
lhs |
|
| System.String |
rhs |
|
Returns
| Type |
Description |
| System.Boolean |
|
GetHashCodeIgnoreCase(String)
Helper function that performs case-insensitive GetHashcode for string using invariant comparison.
Use this in conjunction with EqualsIgnoreCase
Declaration
public static int GetHashCodeIgnoreCase(this string str)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
Returns
| Type |
Description |
| System.Int32 |
|
GetHashCodeOrdIgnoreCase(String)
Helper function that performs case-insensitive GetHashcode for string using ordinal comparison.
Use this in conjunction with EqualsOrdIgnoreCase
Declaration
public static int GetHashCodeOrdIgnoreCase(this string str)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
Returns
| Type |
Description |
| System.Int32 |
|
GetHashCodeOrdSenseCase(String)
Helper function that performs case-insensitive GetHashcode for string using ordinal comparison.
Use this in conjunction with EqualsOrdSenseCase
Declaration
public static int GetHashCodeOrdSenseCase(this string str)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
Returns
| Type |
Description |
| System.Int32 |
|
GetHashCodeSenseCase(String)
Helper function that performs GetHashcode for string using invariant comparison.
Use this in conjunction with EqualsSenseCase
Declaration
public static int GetHashCodeSenseCase(this string str)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
Returns
| Type |
Description |
| System.Int32 |
|
IndexToLineNumber(String, Int32)
Converts an index in a string into a line number, counting new line characters
Declaration
public static int IndexToLineNumber(this string str, int index)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
| System.Int32 |
index |
|
Returns
| Type |
Description |
| System.Int32 |
|
IsNotNullOrEmpty(String)
Helper function that calls !string.IsNullOrEmpty()
Declaration
public static bool IsNotNullOrEmpty(this string s)
Parameters
| Type |
Name |
Description |
| System.String |
s |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsNotNullOrWhiteSpace(String)
Helper function that calls !string.IsNullOrWhiteSpace()
Declaration
public static bool IsNotNullOrWhiteSpace(this string s)
Parameters
| Type |
Name |
Description |
| System.String |
s |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsNullOrEmpty(String)
Helper function that calls string.IsNullOrEmpty()
Declaration
public static bool IsNullOrEmpty(this string s)
Parameters
| Type |
Name |
Description |
| System.String |
s |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsNullOrWhiteSpace(String)
Helper function that calls string.IsNullOrWhiteSpace()
Declaration
public static bool IsNullOrWhiteSpace(this string s)
Parameters
| Type |
Name |
Description |
| System.String |
s |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsOneOf(String, IEnumerable<String>)
Returns true if the specified string is one of the specified.
The comparison is invariant case-insensitive. No trimming is performed
Declaration
public static bool IsOneOf(this string val, IEnumerable<string> strings)
Parameters
| Type |
Name |
Description |
| System.String |
val |
|
| System.Collections.Generic.IEnumerable<System.String> |
strings |
|
Returns
| Type |
Description |
| System.Boolean |
|
IsOneOf(String, String[])
Returns true if the specified string is one of the specified.
The comparison is invariant case-insensitive. No trimming is performed
Declaration
public static bool IsOneOf(this string val, params string[] strings)
Parameters
| Type |
Name |
Description |
| System.String |
val |
|
| System.String[] |
strings |
|
Returns
| Type |
Description |
| System.Boolean |
|
SplitLines(String)
Splits string into lines using Win or .nix line brakes
Declaration
public static string[] SplitLines(this string str)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
Returns
| Type |
Description |
| System.String[] |
|
TakeFirstChars(String, Int32, String)
Takes first X chars from a string. If string is null returns null. If string does not have enough
the function returns what the string has
Declaration
public static string TakeFirstChars(this string str, int count, string ellipsis = null)
Parameters
| Type |
Name |
Description |
| System.String |
str |
|
| System.Int32 |
count |
|
| System.String |
ellipsis |
|
Returns
| Type |
Description |
| System.String |
|
ToLinuxLines(String)
Declaration
public static string ToLinuxLines(this string src)
Parameters
| Type |
Name |
Description |
| System.String |
src |
|
Returns
| Type |
Description |
| System.String |
|
ToWindowsLines(String)
Declaration
public static string ToWindowsLines(this string src)
Parameters
| Type |
Name |
Description |
| System.String |
src |
|
Returns
| Type |
Description |
| System.String |
|