digitalmars.D - How do I advance an array ?
- Tal (14/14) Nov 18 2006 Hello, I'm new to D, my origin is C++.
- Lionello Lunesu (2/2) Nov 18 2006 bfr[i..$] will give you the subset from i till (but not including) bft's...
- Chris Nicholson-Sauls (11/31) Nov 18 2006 "Pointer magic" does not apply to D arrays, as they are not just flat po...
- Chris Miller (8/12) Nov 18 2006 Looks like it will also match with:
- %u (1/1) Nov 18 2006 Thanx a lot.
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
bfr[i..$] will give you the subset from i till (but not including) bft's length ($ is short for length).
Nov 18 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: 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
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