www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How do I advance an array ?

reply Tal <talgamma gmail.com> writes:
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
Nov 18 2006
next sibling parent "Lionello Lunesu" <lionello lunesu.remove.com> writes:
bfr[i..$] will give you the subset from i till (but not including) bft's 
length ($ is short for length).
Nov 18 2006
prev sibling next sibling parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
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: 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
Nov 18 2006
prev sibling parent reply "Chris Miller" <chris dprogramming.com> writes:
On Sat, 18 Nov 2006 15:33:42 -0500, Tal <talgamma gmail.com> wrote:

 char[] bfr;
 bfr =3D cast(char[]) read (ini_path);
 int i =3D find (bfr,"[D]");
 i =3D find (bfr+i, "Compilator File=3D");
Looks like it will also match with: [Foo] bar=3Dthis [D] is not a section. but to get a substring: bfr[i .. bfr.length] Note: there is an .ini file module at http://www.dprogramming.com/ini.ph= p
Nov 18 2006
parent %u <talgamma gmail.com> writes:
Thanx a lot.
Nov 18 2006