Jeffrey LeCours Jeffrey LeCours - 3 years ago 109
C# Question

What are the methods for tokenizing strings in .Net?

This must be a classic .NET question for anyone migrating from Java.

.NET does not seem to have a direct equivalent to, however the JLCA provides a SupportClass that attempts to implement it. I believe the JLCA also provides a Tokenizer SupportClass that takes a String as the source, which I thought a StreamTokenizer would be derived from, but isn't.

What is the preferred way to Tokenize both a Stream and a String? or is there one? How are streams tokenized in .Net? I'd like to have the flexibility that provides. Any thoughts?

Answer Source

There isn't anything in .NET that is completely equivalent to StreamTokenizer. For simple cases, you can use String.Split(), but for more advanced token parsing, you'll probably end up using System.Text.RegularExpressions.Regex.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download