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)
- String1 = “AB CD5 EFG10 HI2 AB” (mC..Value.Split)
- Results1: (multiCode)
- AB (m)
- CD5 (m)
- EFG10 (m)
- HI2 (m)
-
AB (m)
-
String2 = “MN3 MN4 OP8 EXT1000 QR 3”
- Results2:
- MN3
- MN4
- OP8 EXT1000 (should skip space because “EXT” isn’t in list)
-
QR 3 (should skip space because “3” isn’t in list)
Dim multiPoint As IEnumerable(Of XElement) = _
From mPoint In xdoc….ReverseDim multiCode = _
From mC In multiPoint _
From m In mC..Value.Split _
Select mFor Each cd In multiCode
Console.WriteLine(cd)
Next
1 Answer