'Getting specific lines of data from a string
I use Mailkit and it has a function that fetch me email body text GetMessage().Textbody
, i want to get specific lines of email body that contain specific strings
For example:
12313 banana milkshake 12356 choco milkshake kiwi milkshake 1231313
and goes on....
I want to get from the 700 lines of email text body only 2 lines that contains the word "kiwi" and "choco"
Using reader As New StreamReader("mail.txt")
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains("kiwi" or "choco") Then
Console.WriteLine(line)
Exit While
End If
End While
End Using
i've been trying to find a better and faster way instead of saving string to file then using this
Solution 1:[1]
in c# since I dont know vb.net but you can translate
string msg = GetMessage().TextBody();
var lines = msg.Split('\n');
var res = lines.Where(l=>(l.Contains("kiwi") || l.Contains("choco")));
if the linq stuff doesnt translate well to vb.net then do
var res = new List<string>();
foreach(var l in lines)
{
if (l.Contains("kiwi") || l.Contains("choco"))
{
res.Add(l);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
