string and char[] conflict

qadasd asd at asd.vi
Sun Mar 9 05:13:08 PDT 2008


I use a foreach to iterate thourgh the lines of a text file:

foreach(ulong lnumber, char[] line; input)

and I use std.string:strip() to take out unnecessary spaces:

line=strip(line);

Which gives out the following error:
test.d(142): function std.string.strip (invariant(char)[]) does not 
match parameter types (char[])
test.d(142): Error: cannot implicitly convert expression (line) of type 
char[] to invariant(char)[]
test.d(142): Error: cannot implicitly convert expression 
(strip(cast(invariant(char)[])line)) of type invariant(char)[] to char[]

changing the line will correct the problem:

line=strip(line.idup).dup;

Is there a cleaner way to do this?

I tried using

foreach(ulong lnumber, string line; input)

but it wont compile:

test.d(136): function std.stream.InputStream.opApply (int delegate(ref 
char[] line)) does not match parameter
  types (int delegate(ref ulong __applyArg0, ref invariant(char)[] 
__applyArg1))
test.d(136): Error: cannot implicitly convert expression 
(__foreachbody15) of type int delegate(ref ulong __a
pplyArg0, ref invariant(char)[] __applyArg1) to int delegate(ref ulong 
n, ref wchar[] line)

As you might have assumed, im using lastest DMD2.


More information about the Digitalmars-d-learn mailing list