Skip to content

Instantly share code, notes, and snippets.

@ngbrown
Created June 19, 2010 17:03
Show Gist options
  • Save ngbrown/445063 to your computer and use it in GitHub Desktop.
Save ngbrown/445063 to your computer and use it in GitHub Desktop.
Examples of using TextScanner
namespace ScanSum
{
using System;
using System.Globalization;
using System.IO;
using TextScanner;
internal class ScanSum
{
private static void Main(string[] args)
{
TextScanner s = null;
double sum = 0;
try
{
s = new TextScanner(new StreamReader("usnumbers.txt"));
s.UseCulture(new CultureInfo("en-US"));
while (s.HasNext())
{
if (s.HasNextDouble())
{
sum += s.NextDouble();
}
else
{
s.Next();
}
}
}
finally
{
if (s != null)
{
s.Close();
}
}
Console.WriteLine(sum);
}
}
}
namespace ScanXan
{
using System;
using System.IO;
using TextScanner;
internal class ScanXan
{
private static void Main(string[] args)
{
TextScanner s = null;
try
{
s = new TextScanner(new StreamReader("xanadu.txt"));
while (s.HasNext())
{
Console.WriteLine(s.Next());
}
}
finally
{
if (s != null)
{
s.Close();
}
}
}
}
}
namespace ScanXan
{
using System;
using System.IO;
using TextScanner;
internal class ScanXan
{
private static void Main(string[] args)
{
using (var s = new TextScanner(new StreamReader("xanadu.txt")))
{
foreach (var token in s)
{
Console.WriteLine(token);
}
}
}
}
}
8.5
32,767
3.14159
1,000,000.1
In Xanadu did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment