sscanf

  • Thread starter Thread starter Hin
  • Start date Start date
H

Hin

Anyone knows if there is any method similar to the C++ sscanf in C#?
(parse a string that contains several values)
 
Theres no statement exactly like scanf. StreamReader is pretty good class to
read file

System.IO.StreamReader stream = new StreamReader(testFileName);
stream.BaseStream.Seek(0, SeekOrigin.Begin);
while (stream.Peek() > -1)
{
stream.ReadLine(); //equal to scanf
}
stream.Close();
 
Regular expressions are a quite powerful technique to extract data from a
string. And, most simple types have a Parse method (int.Parse,
double.Parse...). IMO a combination of those two comes closest to "scanf"
(but it more powerful and safer)

Niki
 
Back
Top