H Hin Jun 30, 2004 #1 Anyone knows if there is any method similar to the C++ sscanf in C#? (parse a string that contains several values)
Anyone knows if there is any method similar to the C++ sscanf in C#? (parse a string that contains several values)
S Shakir Hussain Jun 30, 2004 #2 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();
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();
N Niki Estner Jun 30, 2004 #3 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
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