StringExtensionsGetGroupingInfo Method
Gets info about the grooupings of a String.
Namespace: DevCase.Extensions.StringExtensionsAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[EditorBrowsableAttribute(EditorBrowsableState.Always)]
public static GroupingInfo GetGroupingInfo(
this string sender,
List<GroupingCharsInfo> groupingChars = null
)
<ExtensionAttribute>
<EditorBrowsableAttribute(EditorBrowsableState.Always)>
Public Shared Function GetGroupingInfo (
sender As String,
Optional groupingChars As List(Of GroupingCharsInfo) = Nothing
) As GroupingInfo
Dim sender As String
Dim groupingChars As List(Of GroupingCharsInfo)
Dim returnValue As GroupingInfo
returnValue = sender.GetGroupingInfo(groupingChars)
public:
[ExtensionAttribute]
[EditorBrowsableAttribute(EditorBrowsableState::Always)]
static GroupingInfo^ GetGroupingInfo(
String^ sender,
List<GroupingCharsInfo^>^ groupingChars = nullptr
)
[<ExtensionAttribute>]
[<EditorBrowsableAttribute(EditorBrowsableState.Always)>]
static member GetGroupingInfo :
sender : string *
?groupingChars : List<GroupingCharsInfo>
(* Defaults:
let _groupingChars = defaultArg groupingChars null
*)
-> GroupingInfo
No code example is currently available or this language may not be supported.
- sender String
-
The source String.
- groupingChars ListGroupingCharsInfo (Optional)
-
The grouping chars.
If this value is , the default grouping characters are used instead.
The default grouping characters are: "()", "{}" and "[]".
GroupingInfo
A
GroupingInfo object that contains the grouping info.
In Visual Basic and C#, you can call this method as an instance method on any object of type
String. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
This is a code example.
No code example is currently available or this language may not be supported.
Private Sub Test()
Dim source As String() =
{
"This is (good)",
"This (is ({good}))",
"This is good",
"This is (bad))",
"This is (bad",
"This is bad)",
"This is bad)("
}
Dim groupingCharList As New List(Of GroupingCharsInfo) From
{
New GroupingCharsInfo(apertureChar:="("c, closureChar:=")"c),
New GroupingCharsInfo(apertureChar:="{"c, closureChar:="}"c),
New GroupingCharsInfo(apertureChar:="["c, closureChar:="]"c)
}
For Each str As String In source
Dim info As GroupingInfo = str.GetGroupingInfo(groupingCharList)
Dim sb As New Global.System.Text.StringBuilder
With sb
.AppendLine(String.Format("Input String: {0}", info.Source))
.AppendLine()
.Append("Grouping Characters: ")
For Each charInfo As GroupingCharsInfo In groupingCharList
.Append(String.Format("{0}{1} ", charInfo.Aperture, charInfo.Closure))
Next charInfo
.AppendLine()
.AppendLine(String.Format("String has closed agrupations?: {0}", info.HasClosedGroups))
.AppendLine(String.Format("String has opened agrupations?: {0}", info.HasOpenGroups))
.AppendLine()
.AppendLine(String.Format("Closed Agrupations Count: {0}", info.GroupsClosedCount))
.AppendLine(String.Format("Opened Agrupations Count: {0}", info.GroupsOpenCount))
.AppendLine()
.AppendLine("Closed Agrupations indices:")
For Each item As KeyValuePair(Of Integer, Integer) In info.GroupsClosedPositions
.AppendLine(String.Format("Start: {0}, End: {1}", CStr(item.Key), CStr(item.Value)))
Next item
.AppendLine()
.AppendLine(String.Format("Opened Agrupations indices: {0}",
String.Join(", ", info.GroupsOpenPositions)))
End With
MessageBox.Show(sb.ToString(), "Agrupations Information",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Next str
End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
ArgumentNullException
|
groupingChars
|
ArgumentException
|
An aperture character cannot be the same as a closure character.;groupingChars
|