Click here to Skip to main content
15,888,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any easy/reliable way to get the 'ASPxFormLayout1' value from this string.
The value could change - ideally want a method of extracting the data between the quotes after 'ID='

String is :
<dx:ASPxFormLayout ID="ASPxFormLayout1" runat="server" DataSourceID="SqlDataSource1">

What I have tried:

Tried instr but not sure on wildcards? and even if I could find it not sure how to extract what I want. Thanks.
Posted
Updated 2-Feb-18 5:29am

Regular Expression Language - Quick Reference | Microsoft Docs[^]
VB.NET
Dim input As String = "<dx:ASPxFormLayout ID=""ASPxFormLayout1"" runat=""server"" DataSourceID=""SqlDataSource1"">"
Dim m As Match = Regex.Match(input, "\bID=""(?<id>[^""]+)""")
Dim id As String = If(m.Success, m.Groups("id").Value, "")
' id === "ASPxFormLayout1"
 
Share this answer
 
v2
If you mean "get the ID data between the double quotes" then use a regex:
(?<=ID=").+(?="\s*runat=)
Should do it.
VB
Public Dim regex As Regex = New Regex( _
      "(?<=ID="").+(?=""\s*runat=)", _
    RegexOptions.Multiline _
    Or RegexOptions.Singleline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.Compiled _
    )

'...
Dim m As Match = regex.Match(InputText)
If m.Success Then
   Dim id as String = m.Value
   ' ...
End If
 
Share this answer
 
Comments
Richard Deeming 2-Feb-18 11:30am    
That one only works if the runat= immediately follows the ID. :)
OriginalGriff 2-Feb-18 11:38am    
Then yours needs a '?' after the '+' :laugh:
Richard Deeming 2-Feb-18 11:41am    
Only if you're planning to match an empty ID. But the ternary operator already deals with that. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900