Reputation: 3
I need to parse and separate input strings using VB.NET. Split method works in Example 1, but my problem is when I need to “skip” a space if the following value isn’t in the list like Example2. My code works as expected for String1 using Split, but it fails my needs when it outputs EXT1000 and 3 as individual values - they should be part of the original string if not found in the list. I would prefer to keep it in Linq if possible. Generate some type of collection to be used for later manipulation. The main output will end up with a For Each “Results” WriteLine in text file.
list = {“AB”, “CD”, “EFG”, “HI”, …. “MN”, “OP”, “QR”…}
(results from LINQ from external file. I’m not using it in my code yet, but I think I’ll need to incorporate some comparison)
AB (m)
String2 = “MN3 MN4 OP8 EXT1000 QR 3”
QR 3 (should skip space because “3” isn’t in list)
Dim multiPoint As IEnumerable(Of XElement) = _ From mPoint In xdoc....Reverse
Dim multiCode = _ From mC In multiPoint _ From m In mC..Value.Split _ Select m
For Each cd In multiCode Console.WriteLine(cd) Next
Upvotes: 0
Views: 1015
Reputation: 9193
Dim MasterList As String() = {"AB", "CD", "EFG", "HI", "MN", "OP", "QR"}
Dim OtherList As String() = {"AB3", "CD4", "EFG1000", "3"}
Dim DesiredList As String() = (From strValueInMasterList As String In MasterList _
From strValueFromOtherList As String In OtherList _
Where strValueFromOtherList.StartsWith(strValueInMasterList) _
Select strValueFromOtherList).ToArray()
Upvotes: 0