D - String in Multidim.Dynam.Array
- antome (9/9) Nov 27 2003 How can I put a String in a Multi Dimensional Dynamic Array ?
- Ant (6/15) Nov 27 2003 myarray has length = 0 so myarray[0] is out of bounds
- Charles Sanders (15/24) Nov 27 2003 char [] [] thanksgiving;
- Ant (13/23) Nov 27 2003 Don't do:
- Charles Sanders (7/34) Nov 27 2003 Then we need a template library ( having to eat my words earlier of, 'we
- Hauke Duden (9/27) Nov 27 2003 I think delete only works for associative arrays, not regular ones. So
How can I put a String in a Multi Dimensional Dynamic Array ? char[][] myarray; char[] mystring; mystring = "abc..."; // Works!! myarray = split(anystring); mystring = myarray[0]; // Works! myarray[0] = "abc..."; // Works NOT ! myarray[0][] = "abc..."; // Works NOT ! ArrayBoundsError antome
Nov 27 2003
In article <bq571t$18eq$1 digitaldaemon.com>, antome says...How can I put a String in a Multi Dimensional Dynamic Array ? char[][] myarray; char[] mystring; mystring = "abc..."; // Works!! myarray = split(anystring); mystring = myarray[0]; // Works! myarray[0] = "abc..."; // Works NOT ! myarray[0][] = "abc..."; // Works NOT ! ArrayBoundsError antomemyarray has length = 0 so myarray[0] is out of bounds "~=" will append to a dinamic array so it's very simple: myarray ~= "abc..."; Ant
Nov 27 2003
char [] [] thanksgiving; thanksgiving ~= "turkey"; thanksgiving ~= "tort"; thanksgiving ~= "footbal"; However ive been playing with it , and Im not sure how to delete the 2nd element, and have the array resize so that length is 2 and it contains "turkey" and "football" delete thanksgiving[1]; thanksgiving[1] = null; thanksgiving.length = 2; not working you can assign them manually of course, im missing something ? C "antome" <antome_member pathlink.com> wrote in message news:bq571t$18eq$1 digitaldaemon.com...How can I put a String in a Multi Dimensional Dynamic Array ? char[][] myarray; char[] mystring; mystring = "abc..."; // Works!! myarray = split(anystring); mystring = myarray[0]; // Works! myarray[0] = "abc..."; // Works NOT ! myarray[0][] = "abc..."; // Works NOT ! ArrayBoundsError antome
Nov 27 2003
In article <bq5d3q$1hk0$1 digitaldaemon.com>, Charles Sanders says...char [] [] thanksgiving; thanksgiving ~= "turkey"; thanksgiving ~= "tort"; thanksgiving ~= "footbal"; However ive been playing with it , and Im not sure how to delete the 2nd element, and have the array resize so that length is 2 and it contains "turkey" and "football" delete thanksgiving[1]; thanksgiving[1] = null; thanksgiving.length = 2;Don't do: thanksgiving[1..thanksgiving.length-1] = thanksgiving[2..thanksgiving.length]; thanksgiving.length = thanksgiving.length-1; The compiler will accept that (and actualy runs fine on some DMD versions) but the manual says it illegal. inserting with the same slicing technic will not run as expected. you must cycle through the array to shift the elements. do the same thing to insert. but, of course, arrays aren't suppose to be used when you need to delete and inserting elements frequently. I guess that's why Walter doesn't want to implement the "smart" overlap slicing. Ant
Nov 27 2003
Then we need a template library ( having to eat my words earlier of, 'we dont need no stinking STL' ). Hmmmm. C "Ant" <Ant_member pathlink.com> wrote in message news:bq5f9s$1l4d$1 digitaldaemon.com...In article <bq5d3q$1hk0$1 digitaldaemon.com>, Charles Sanders says...thanksgiving[2..thanksgiving.length];char [] [] thanksgiving; thanksgiving ~= "turkey"; thanksgiving ~= "tort"; thanksgiving ~= "footbal"; However ive been playing with it , and Im not sure how to delete the 2nd element, and have the array resize so that length is 2 and it contains "turkey" and "football" delete thanksgiving[1]; thanksgiving[1] = null; thanksgiving.length = 2;Don't do: thanksgiving[1..thanksgiving.length-1] =thanksgiving.length = thanksgiving.length-1; The compiler will accept that (and actualy runs fine on some DMD versions) but the manual says it illegal. inserting with the same slicing technic will not run as expected. you must cycle through the array to shift the elements. do the same thing to insert. but, of course, arrays aren't suppose to be used when you need to delete and inserting elements frequently. I guess that's why Walter doesn't want to implement the "smart" overlap slicing. Ant
Nov 27 2003
Charles Sanders wrote:char [] [] thanksgiving; thanksgiving ~= "turkey"; thanksgiving ~= "tort"; thanksgiving ~= "footbal"; However ive been playing with it , and Im not sure how to delete the 2nd element, and have the array resize so that length is 2 and it contains "turkey" and "football" delete thanksgiving[1]; thanksgiving[1] = null; thanksgiving.length = 2; not working you can assign them manually of course, im missing something ? CI think delete only works for associative arrays, not regular ones. So what you're really doing is deleting the string object itself, not the array slot. So I guess you're stuck with manually moving the elements down. [ This is another example why delete shouldn't be used to delete slots in associative arrays. It just soooo inconsistent and confusing. We need a different operator/method for deleting array slots!] Hauke
Nov 27 2003