digitalmars.D - does std.file.slurp work with string data field?
- Big Tummy (19/19) Dec 26 2013 I have a file containing data like,
- bearophile (6/7) Dec 26 2013 Use (I also have added a space after the second %s because slurp
- bearophile (5/6) Dec 26 2013 Sorry, ignore this because it's essentially the same code as
- Big Tummy (15/23) Dec 26 2013 Not working for me. It seems to have something to do with string
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/30) Dec 26 2013 dmd git head compiles your code. Use the cutting edge dmd or please wait...
I have a file containing data like, --- data.txt --- abc, 1 def, 2 --- end data.txt --- I try to read in the data like following, but the the codes do not compile: --- mytest.d --- import std.file, std.stdio; void main() { auto arr = "data.txt".slurp!(string, int)("%s, %s"); foreach(a; arr) { writefln("%s: %d", a[0], a[1]); } } --- end mytest.d --- Any idea? Thanks in advance, Big Tummy
Dec 26 2013
Big Tummy:auto arr = "data.txt".slurp!(string, int)("%s, %s");Use (I also have added a space after the second %s because slurp is buggy with Windows-style newlines): auto arr = slurp!(string, int)("data.txt", "%s, %s "); Bye, bearophile
Dec 26 2013
auto arr = slurp!(string, int)("data.txt", "%s, %s ");Sorry, ignore this because it's essentially the same code as yours. What's the error you are receiving? (And better to ask such questions in D.learn). Bye, bearophile
Dec 26 2013
On Friday, 27 December 2013 at 02:05:42 UTC, bearophile wrote:Big Tummy:Not working for me. It seems to have something to do with string not being swappable:auto arr = "data.txt".slurp!(string, int)("%s, %s");Use (I also have added a space after the second %s because slurp is buggy with Windows-style newlines): auto arr = slurp!(string, int)("data.txt", "%s, %s "); Bye, bearophilerdmd mytest.dcore.exception.AssertError std.algorithm(1942): Assertion failure ---------------- /tmp/.rdmd-1001/rdmd-my2.d-AEA8686B37E3195901320EEC6C7A9E25/ y2(_d_assertm+0x16) [0x80b0766] /tmp/.rdmd-1001/rdmd-my2.d-AEA8686B37E3195901320EEC6C7A9E25/my2() [0x80b4a3a] /tmp/.rdmd-1001/rdmd-my2.d-AEA8686B37E3195901320EEC6C7A9E25/my2(pure nothrow trusted void std.algorithm.swap!(std.typecons.Tuple!(immutable(char)[], int).Tuple).swap(ref std.typecons.Tuple!(immutable(char)[], int).Tuple, ref std.typecons.Tuple!(immutable(char)[], int).Tuple)+0x59) [0x80aae01]
Dec 26 2013
On 12/26/2013 06:16 PM, Big Tummy wrote:On Friday, 27 December 2013 at 02:05:42 UTC, bearophile wrote:dmd git head compiles your code. Use the cutting edge dmd or please wait for the next release. :) AliBig Tummy:Not working for me. It seems to have something to do with string not being swappable:auto arr = "data.txt".slurp!(string, int)("%s, %s");Use (I also have added a space after the second %s because slurp is buggy with Windows-style newlines): auto arr = slurp!(string, int)("data.txt", "%s, %s "); Bye, bearophilerdmd mytest.dcore.exception.AssertError std.algorithm(1942): Assertion failure ---------------- /tmp/.rdmd-1001/rdmd-my2.d-AEA8686B37E3195901320EEC6C7A9E25/my2(_d_assertm+0x16) [0x80b0766] /tmp/.rdmd-1001/rdmd-my2.d-AEA8686B37E3195901320EEC6C7A9E25/my2() [0x80b4a3a] /tmp/.rdmd-1001/rdmd-my2.d-AEA8686B37E3195901320EEC6C7A9E25/my2(pure nothrow trusted void std.algorithm.swap!(std.typecons.Tuple!(immutable(char)[], int).Tuple).swap(ref std.typecons.Tuple!(immutable(char)[], int).Tuple, ref std.typecons.Tuple!(immutable(char)[], int).Tuple)+0x59) [0x80aae01]
Dec 26 2013