/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System.Text/RegularExpressions/Overview/vb/caching1.vb
52 строки
2 KB
Genevieve Warren
Add remarks for core types (#38970)
05 янв 2024, 22:14
Не верифицирован
05 янв 2024, 22:14
71d1377
Код
Авторство
О чём код?
' Visual Basic .NET Document Option Strict On Imports System.IO Imports System.Text.RegularExpressions Module Example Public Sub Main() Dim filename As String = ".\Caching1.txt" ' <Snippet1> Dim sr As New StreamReader(filename) Dim input As String Dim pattern As String = "\b(\w+)\s\1\b" Do While sr.Peek() >= 0 input = sr.ReadLine() Dim rgx As New Regex(pattern, RegexOptions.IgnoreCase) Dim matches As MatchCollection = rgx.Matches(input) If matches.Count > 0 Then Console.WriteLine("{0} ({1} matches):", input, matches.Count) For Each match As Match In matches Console.WriteLine(" " + match.Value) Next End If Loop sr.Close() ' </Snippet1> Console.WriteLine() Main2() End Sub Public Sub Main2() Dim filename As String = ".\Caching1.txt" ' <Snippet2> Dim sr As New StreamReader(filename) Dim input As String Dim pattern As String = "\b(\w+)\s\1\b" Dim rgx As New Regex(pattern, RegexOptions.IgnoreCase) Do While sr.Peek() >= 0 input = sr.ReadLine() Dim matches As MatchCollection = rgx.Matches(input) If matches.Count > 0 Then Console.WriteLine("{0} ({1} matches):", input, matches.Count) For Each match As Match In matches Console.WriteLine(" " + match.Value) Next End If Loop sr.Close() ' </Snippet2> Console.WriteLine() End Sub End Module