Class StringExtensions
Useful extension methods for String.
Inherited Members
Namespace: IRM
Assembly: IRM.dll
Syntax
public static class StringExtensions
Methods
AddCheckNumber(String)
Calculates the check number according to the Luhn algoritm and adds it to the end.
Declaration
public static string AddCheckNumber(this string str)
Parameters
String
str
The string to calculate and add check number for. |
Returns
String
The original |
AddLengthAndCheckNumber(String)
Calculates the length and the check number according to the Luhn algoritm and adds them to the end.
Declaration
public static string AddLengthAndCheckNumber(this string str)
Parameters
String
str
The string to calculate and add length and check number for. |
Returns
String
The original |
Remarks
The length calculation will include the check number and will always be one position. For string with greater length than 9 a modules 10 is done. The format of the returned string is [orginal string][length mod 10][check number].
AddQueryString(String, String)
Adds a query part to a string that represents an url, handling ? and & correctly.
Declaration
public static string AddQueryString(this string url, string query)
Parameters
String
url
The current url. |
String
query
The query to add (name=value) |
Returns
String
A string with the query added. |
AsCollection(String, Char)
Splits a string into a collection of strings.
Declaration
public static ICollection<string> AsCollection(this string str, char separator = ' ')
Parameters
String
str
The string to split. |
Char
separator
The seperator charachter. |
Returns
System.Collections.Generic.ICollection<String>
Returns a collection of strings. |
ComputeLuhn(String)
Calculates the check number according to the Luhn algoritm.
Declaration
public static string ComputeLuhn(this string number)
Parameters
String
number
The string to calculate check number for. |
Returns
String
The check number for |
ConvertTo(String, Type)
Converts a string to the specified type.
Declaration
public static object ConvertTo(this string str, Type type)
Parameters
String
str
The String to convert. |
System.Type
type
The type to convert the string to. |
Returns
Object
An Object that represents the converted text. |
Exceptions
System.NotSupportedException
The conversion cannot be performed. |
ConvertTo<T>(String)
Converts a string to the specified type.
Declaration
public static T ConvertTo<T>(this string str)
Parameters
String
str
The String to convert. |
Returns
T
An |
Type Parameters
T
The type to convert the string to. |
Exceptions
System.NotSupportedException
The conversion cannot be performed. |
CreateSentence(String)
Creates a "normal" sentence from a class name or method name.
Declaration
public static string CreateSentence(this string str)
Parameters
String
str
The String to create a sentence from. |
Returns
String
A sentence with whitespace and normalized casing. |
Remarks
"This_Is_An_Example" will result in "This is an example".
EnsureLeadingSlash(String)
Ensures that the url
string begins with a slash.
Declaration
public static string EnsureLeadingSlash(this string url)
Parameters
String
url
The url. |
Returns
String
A string with a slash in the beginning. |
EnsureTrailingSlash(String)
Ensures that the url
string has a trailing slash.
Declaration
public static string EnsureTrailingSlash(this string url)
Parameters
String
url
The url. |
Returns
String
A string with a trailing slash. |
Formatera(String, Object[])
Replaces the format item in a string with the representation of a corresponding object in the specified array.
Declaration
public static string Formatera(this string str, params object[] args)
Parameters
String
str
The composite format string. |
Object[]
args
An object array that contains zero or more objects to format. |
Returns
String
A copy of |
FormateraOrgNr(String)
Formats a string as an organisation number, aka adding the dash before the last four digits.
Declaration
public static string FormateraOrgNr(this string str)
Parameters
String
str
The string to format. |
Returns
String
Returns a new string with the dash inserted before the last four digits. |
FromBase64(String)
Decodes a string that is encoded with base-64 digits to its equivalent string representation.
Declaration
public static string FromBase64(this string str)
Parameters
String
str
The string to decode. |
Returns
String
The string decoded. |
Remarks
If str
is not base-64 encoded it will be returned as is (not throwing any exception).
IsBase64Encoded(String)
Gets if a string is encoded as Base64 or not.
Declaration
public static bool IsBase64Encoded(this string str)
Parameters
String
str
The string to check if it is base 64 encoded. |
Returns
Boolean
true if the string is base 64 encoded; otherwise false. |
IsEpost(String)
Gets if a string is an valid email address.
Declaration
public static bool IsEpost(this string str)
Parameters
String
str
The string to check if it is an email address. |
Returns
Boolean
true if the string represents an valid email address; otherwise false. |
IsLuhn(String)
Gets if a string is valid according to the Luhn algoritm, for example a social security number.
Declaration
public static bool IsLuhn(this string str)
Parameters
String
str
The string to check if it is valid according to the Luhn aloritm. |
Returns
Boolean
true if the string is valid according to the Luhn algoritm; otherwise false. |
IsOnlyDigits(String)
Gets if the string only contains digits.
Declaration
public static bool IsOnlyDigits(this string str)
Parameters
String
str
|
Returns
Boolean
|
IsSwedishOrganizationalNumber(String)
Gets if a string is a valid swedish organizational number.
Declaration
public static bool IsSwedishOrganizationalNumber(this string str)
Parameters
String
str
The string to check if it is a swedish organizational number. |
Returns
Boolean
true if the string represents a valid swedish organizational number; otherwise false. |
IsSwedishPersonnummer(String)
Gets if a string is a valid swedish person number.
Declaration
public static bool IsSwedishPersonnummer(this string str)
Parameters
String
str
The string to check if it is a swedish person number. |
Returns
Boolean
true if the string represents a valid swedish person number; otherwise false. |
IsUrl(String)
Gets if a string is an valid URL.
Declaration
public static bool IsUrl(this string str)
Parameters
String
str
The string to check if it is an URL. |
Returns
Boolean
true if the string represents an valid URL; otherwise false. |
IsVatNumber(String)
Gets if a string is a valid VAT number.
Declaration
public static bool IsVatNumber(this string str)
Parameters
String
str
The string to check if it is a VAT number. |
Returns
Boolean
true if the string represents a valid VAT number; otherwise false. |
KontinentAsText(Kontinenter)
Ger kontinentens namn utifrån Kontinenter.
Declaration
public static string KontinentAsText(this Kontinenter kontinent)
Parameters
Kontinenter kontinent |
Returns
String
Landets namn enligt användarens språk. |
KontinentAsText(Kontinenter, CultureInfo)
Ger kontinentens namn utifrån Kontinenter.
Declaration
public static string KontinentAsText(this Kontinenter kontinent, CultureInfo culture)
Parameters
Kontinenter kontinent |
System.Globalization.CultureInfo
culture
An object that represents the culture for which the |
Returns
String
Kontinentens namn enligt användarens språk. |
KorrigeraNull(String)
Declaration
public static string KorrigeraNull(this string str)
Parameters
String
str
|
Returns
String
|
LandkodAsText(String)
Ger landets namn utifrån landkoden (enligt ISO-3166-1).
Declaration
public static string LandkodAsText(this string landKod)
Parameters
String
landKod
Landkoden enligt ISO-3166-1. |
Returns
String
Landets namn enligt användarens språk. |
LandkodAsText(String, CultureInfo)
Ger landets namn utifrån landkoden (enligt ISO-3166-1).
Declaration
public static string LandkodAsText(this string landKod, CultureInfo culture)
Parameters
String
landKod
Landkoden enligt ISO-3166-1. |
System.Globalization.CultureInfo
culture
An object that represents the culture for which the |
Returns
String
Landets namn enligt användarens språk. |
RemoveLeadingSlash(String)
Ensures that the url
string does not begin with a slash.
Declaration
public static string RemoveLeadingSlash(this string url)
Parameters
String
url
The url. |
Returns
String
A string without a slash in the beginning. |
RemoveTrailingSlash(String)
Ensures that the url
string does not have a trailing slash.
Declaration
public static string RemoveTrailingSlash(this string url)
Parameters
String
url
The url. |
Returns
String
A string without a trailing slash. |
SplitCsv(String, Char)
Splits a comma seperated string into a list of strings.
Declaration
public static List<string> SplitCsv(this string csv, char separator = ',')
Parameters
String
csv
The comma seperated string. |
Char
separator
The seperator charachter. |
Returns
List<String>
Returns a list of strings. |