Created
June 19, 2010 17:03
-
-
Save ngbrown/445063 to your computer and use it in GitHub Desktop.
Examples of using TextScanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8.5 | |
32,767 | |
3.14159 | |
1,000,000.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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