Sitecore 5.0 API

StringUtil.GetPrefix Method (String, Char, String)

Gets the prefix part of a string.

[Visual Basic]
Overloads Public Shared Function GetPrefix( _
   ByVal text As String, _
   ByVal delimiter As Char, _
   ByVal defaultValue As String _
) As String
[C#]
public static string GetPrefix(
   string text,
   char delimiter,
   string defaultValue
);

Parameters

text
A string
delimiter
The character delimiting the prefix from the rest of the string.
defaultValue
Value to return if delimiter is not found in text

Return Value

All characters of the string up to the first occurrence of delimiter.

If delimiter is not found in the string, defaultValue is returned.

Example

  string prefix = StringUtil.GetPrefix("sc:menu", ':');
  MainUtil.Out(prefix);
Outputs: sc

See Also

StringUtil Class | Sitecore Namespace | StringUtil.GetPrefix Overload List | Right | Mid