Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for C# equivalent of scanf

Tags:

c#

scanf

I used to code in C language in the past and I found the scanf function very useful. Unfortunately, there is no equivalent in C#.

I am using using it to parse semi-structured text files.

I found an interresting example of scanf implementation here. Unfortunately, it looks old and incomplete.

Does anyone know a scanf C# implementation ? Or at least something that would work as a reversed string.Format?

like image 727
Larry Avatar asked Jan 23 '09 07:01

Larry


People also ask

What is a for loop in C?

The for loop in C language is used to iterate the statements or a part of the program several times. It is frequently used to traverse the data structures like the array and linked list.

How do I start learning C?

Get started with C. Official C documentation - Might be hard to follow and understand for beginners. Visit official C Programming documentation. Write a lot of C programming code - The only way you can learn programming is by writing a lot of code.

What was C originally used for?

C was designed as a minimalist language to be used in writing operating systems for minicomputers, such as the DEC PDP 7, which had very limited memories compared with the mainframe computers of the period. The language was devised during 1969–73, alongside the early development of the UNIX operating system.


2 Answers

Since the files are "semi-structured" can't you use a combination of ReadLine() and TryParse() methods, or the Regex class to parse your data?

like image 186
Mitch Wheat Avatar answered Sep 24 '22 04:09

Mitch Wheat


If regular expressions aren't working for you, I've just posted a sscanf() replacement for .NET. The code can be viewed and downloaded at http://www.blackbeltcoder.com/Articles/strings/a-sscanf-replacement-for-net.

like image 39
Jonathan Wood Avatar answered Sep 24 '22 04:09

Jonathan Wood