using System;
using System.Text.RegularExpressions;
namespace Applications.ConsoleApps
{
public class ConsoleParser
{
public static void Main()
{
Console.WriteLine("Enter any text, followed by <Enter>:\n");
String? s = Console.ReadLine();
ShowWords(s ?? "You didn't enter anything.");
Console.Write("\nPress any key to continue... ");
Console.ReadKey();
}
private static void ShowWords(String s)
{
String pattern = @"\w+";
var matches = Regex.Matches(s, pattern);
if (matches.Count == 0)
{
Console.WriteLine("\nNo words were identified in your input.");
}
else
{
Console.WriteLine($"\nThere are {matches.Count} words in your string:");
for (int ctr = 0; ctr < matches.Count; ctr++)
{
Console.WriteLine($" #{ctr,2}: '{matches[ctr].Value}' at position {matches[ctr].Index}");
}
}
}
}
}
Imports System.Text.RegularExpressions
Namespace Applications.ConsoleApps
Public Module ConsoleParser
Public Sub Main()
Console.WriteLine("Enter any text, followed by <Enter>:")
Console.WriteLine()
Dim s = Console.ReadLine()
ShowWords(s)
Console.Write($"{vbCrLf}Press any key to continue... ")
Console.ReadKey()
End Sub
Private Sub ShowWords(s As String)
Dim pattern = "\w+"
Dim matches = Regex.Matches(s, pattern)
Console.WriteLine()
If matches.Count = 0 Then
Console.WriteLine("No words were identified in your input.")
Else
Console.WriteLine($"There are {matches.Count} words in your string:")
For ctr = 0 To matches.Count - 1
Console.WriteLine($" #{ctr,2}: '{matches(ctr).Value}' at position {matches(ctr).Index}")
Next
End If
Console.WriteLine()
End Sub
End Module
End Namespace
using System;
using System.Text.RegularExpressions;
namespace Applications.ConsoleApps
{
public class ConsoleParser
{
public static void Main()
{
Console.WriteLine("Enter any text, followed by <Enter>:\n");
String? s = Console.ReadLine();
ShowWords(s ?? "You didn't enter anything.");
Console.Write("\nPress any key to continue... ");
Console.ReadKey();
}
private static void ShowWords(String s)
{
String pattern = @"\w+";
var matches = Regex.Matches(s, pattern);
if (matches.Count == 0)
{
Console.WriteLine("\nNo words were identified in your input.");
}
else
{
Console.WriteLine($"\nThere are {matches.Count} words in your string:");
for (int ctr = 0; ctr < matches.Count; ctr++)
{
Console.WriteLine($" #{ctr,2}: '{matches[ctr].Value}' at position {matches[ctr].Index}");
}
}
}
}
}
Imports System.Text.RegularExpressions
Namespace Applications.ConsoleApps
Public Module ConsoleParser
Public Sub Main()
Console.WriteLine("Enter any text, followed by <Enter>:")
Console.WriteLine()
Dim s = Console.ReadLine()
ShowWords(s)
Console.Write($"{vbCrLf}Press any key to continue... ")
Console.ReadKey()
End Sub
Private Sub ShowWords(s As String)
Dim pattern = "\w+"
Dim matches = Regex.Matches(s, pattern)
Console.WriteLine()
If matches.Count = 0 Then
Console.WriteLine("No words were identified in your input.")
Else
Console.WriteLine($"There are {matches.Count} words in your string:")
For ctr = 0 To matches.Count - 1
Console.WriteLine($" #{ctr,2}: '{matches(ctr).Value}' at position {matches(ctr).Index}")
Next
End If
Console.WriteLine()
End Sub
End Module
End Namespace