How do I advance an array ?
    Chris Nicholson-Sauls 
    ibisbasenji at gmail.com
       
    Sat Nov 18 12:43:07 PST 2006
    
    
  
Tal wrote:
> Hello, I'm new to D, my origin is C++.
> 
> I want to search for a value in an ini file. I search for the right section,
> e.g. "[D]", and then I want to find the variable, like "variable=", and then
> change it's value.
> 
> This is how I try to do it:
> 
> char[] bfr;
> bfr = cast(char[]) read (ini_path);
> int i = find (bfr,"[D]");
> i = find (bfr+i, "Compilator File=");
> 
> Since bfr is "char[]" and i is "int" it's erroneous. However none of my trials
> to bypass this type-problem were successful.
> 
> How do I do it ?
> 
> Thanx in advance,
> Tal
"Pointer magic" does not apply to D arrays, as they are not just flat pointers, but a 
structure of a pointer and length.  Assuming your INI requires entities be on a line 
alone, you could break the string into lines first.  Or, you could use a slice.  Example:
# char[] bfr ;
# bfr = cast(char[]) read(ini_path);
# int i = find(bfr, "[D]");
# i = find(bfr[i .. $], "Compilator File=");
That said, it might actually be easier to go with lines, or just parse out the entire 
file, manipulate, and dump back to disc.
-- Chris Nicholson-Sauls
    
    
More information about the Digitalmars-d
mailing list