www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Skiping whitespace

reply "matovitch" <camille.brugel laposte.net> writes:
Hello,

I am writting a simple parser for .obj file (mesh) and I would 
like to read 3 floats like this :

    1.1       2.2

3.3

So I tried file.readf("%*[ \n\t]%f%*[ \n\t]%f%*[ \n\t]%f",&x, &y, 
&z); who works with C function scanf but doesn't work here.

Is there a simple way to parse this text ?

It is said in std.format that "It's comparable to C99's 
vsprintf()". So it is useful for writting but it would have been 
great to have an other format to read which would support regexp.

Thanks.
May 26 2013
next sibling parent "matovitch" <camille.brugel laposte.net> writes:
I should have created this thread in "learning D"...:/
May 26 2013
prev sibling next sibling parent "matovitch" <camille.brugel laposte.net> writes:
up ?
May 26 2013
prev sibling next sibling parent "Mr. Anonymous" <mailnew4ster gmail.com> writes:
On Sunday, 26 May 2013 at 22:07:29 UTC, matovitch wrote:
 up ?

I think you'd better repost it on digitalmars.D.learn.
May 26 2013
prev sibling next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 05/26/2013 05:03 AM, matovitch wrote:

 I am writting a simple parser for .obj file (mesh) and I would like to
 read 3 floats like this :

     1.1       2.2

 3.3

 So I tried file.readf("%*[ \n\t]%f%*[ \n\t]%f%*[ \n\t]%f",&x, &y, &z);
 who works with C function scanf but doesn't work here.

 Is there a simple way to parse this text ?

A single space character in the format specifier is a placeholder for zero or more whitespace characters: import std.stdio; void main() { float x; float y; float z; auto file = File("deneme.txt"); file.readf(" %s %s %s", &x, &y, &z); } Ali
May 26 2013
prev sibling parent "matovitch" <camille.brugel laposte.net> writes:
On Sunday, 26 May 2013 at 23:32:36 UTC, Ali Çehreli wrote:
 A single space character in the format specifier is a 
 placeholder for zero or more whitespace characters:

 import std.stdio;

 void main()
 {
     float x;
     float y;
     float z;

     auto file = File("deneme.txt");

     file.readf(" %s %s %s", &x, &y, &z);
 }

 Ali

Great ! Thanks a lot.
May 27 2013