Data Type - string

System.String


Returning the Length of a Constant

String.Copy("some text").Length 

Hexadecimal Strings


String Literals

A string literal constant is a hard coded string value.
There are two types of string literals in C#.
You have the regular string literal which is enclosed in speech marks.
You also have the verbatim literal which is prefixed with an ampersand character.


Regular String Literals

string myString; 
myString = "C:/temp"
System.Diagnostics.Trace.Write(myString); '= "C:/temp"

myString = "C://temp"
System.Diagnostics.Trace.Write(myString); '= "C://temp"

Some characters cannot be included directly into a string, for example a double quotation mark.
Instead of using just these characters you will have to prefix them with an escape sequence.

myString = "C:\\temp" 
System.Diagnostics.Trace.Write(myString); '= "C:\temp"

myString = "C:\"temp"
System.Diagnostics.Trace.Write(myString); '= "C:"temp"

Handles fixed length strings and do not need editing
The Chars property holds an array of all the characters in a string starting at index 0.


Hard code a string literal

If you want to hard code a string literal to get the length

"Details (" & sMyId & ")" 
= Substring(LEN("Details"))

Properties

CharsGets the character at a specified character position in this instance. In C# this property is the indexer for the string class.
LengthReturns the length of the string.

Methods

CloneReturns a reference to this instance of String.
CompareCompares two strings.
CompareOrdinalCompares two String objects, without considering the local national language or culture.
CompareToCompares this instance with a specified object.
ConcatConcatenates one or more instances of String, or the String representations of the values of one or more instances of Object.
CopyCreates a new string by copying an existing string.
CopyToCopies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters.
EndsWithDetermines whether the end of this instance matches the specified String
EqualsDetermines if two strings are equal (i.e. have the same value).
FormatFormats a string to a particular specification
GetEnumeratorRetrieves an object that can iterate through the individual characters in this instance.
GetHashCodeReturns the hash code for this instance.
GetTypeGets the Type of the current instance.
GetTypeCodeReturns the TypeCode for class String.
IndexOfReturns the index of the first occurrence of a character in a String. This is the equivalent for the VBA InStr() function
IndexOfAnyReturns the index of the first occurrence in any of the characters in an array.
InsertInserts a specified instance of String at a specified index position in this instance.
InternRetrieves the system's reference to the specified String.
IsInterned 
JoinConcatenates a specified separator String between each element of a specified String array, yielding a single concatenated string.
LastIndexOfReturns the index of the last occurrence of a character in a String.
LastIndexOfAnyReturns the index of the last occurrence in any of the characters in an array.
PadLeftRight aligns the characters in the string by padding the left with spaces.
PadRightLeft aligns the characters in the string by padding the right with spaces.
RemoveDeletes the specified number of characters.
ReplaceReplaces all occurrences of a single character with another character or String.
SplitReturns an array. Divides a string, returning the substrings delimited by a specified character.
StartsWithIndicates if a string starts with the specified characters.
SubstringRetrieves a substring from the string.
ToCharArrayCopies the characters from the string to a character array.
ToLowerReturns the text string with all characters converted to lowercase (String).
ToStringConverts the value of this instance to a String.
ToUpperReturns the text string with all the characters converted to uppercase (String).
TrimReturns the text string removing leading and trailing spaces (String).
TrimEndReturns the text string removing only trailing spaces (String).
TrimStartReturns the text string removing only leading spaces (String).

String.Empty

Use this instead of double quotes "".


String.IsNullOrEmpty


Instead of

if ((variable != null) && (variable != String.Empty)) 
{
}

use

if (String.IsNullOrEmpty(variable) 
{
}

String.IsNullOrWhiteSpace

Added in .NET 4.0


Instead of

if (String.IsNullOrEmpty(variable.Trim())) 
{
}

use

if (String.IsNullOrWhiteSpace(variable)) 
{
}

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext