Changes between Version 1 and Version 2 of ForeachStringArrExample
- Timestamp:
- 04/09/06 07:58:21 (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ForeachStringArrExample
v1 v2 11 11 {{{ 12 12 #!d 13 /* 14 This alias makes it a little easier to see what's going on with the 15 dynamic strings (a/k/a "char[]"). 16 */ 17 alias char[] string; 18 13 import std.stdio; 19 14 20 15 void main() { 21 16 22 17 /* create an associative array called "map" */ 18 char[][char[]] map; 23 19 24 string[string] map;25 26 27 /*28 The associate array is populated like this:29 map[key] = value30 */31 32 20 map["abc"] = "apple"; 33 21 map["def"] = "bee"; 34 22 map["xyz"] = "cat"; 35 23 36 37 /* 38 The foreach is used to determine the contents of 39 the associative array. 24 /* The foreach is used to determine the contents of the associative array. 25 Note that the types of 'key' and 'value' are inferred. 40 26 */ 41 27 42 printf("Iterating over map...\n"); 43 foreach (string key, string value; map) 44 { 45 printf("\t%.*s => %.*s\n", key, value); 46 } 28 writefln("Iterating over map..."); 29 foreach (key, value; map) 30 writefln("\t%s => %s", key, value); 47 31 } 48 32 }}} 51 35 52 36 This example was inspired on an example posted by csauls and from comments by larsivi. 53 54 || Link || http://www.dsource.org/tutorials/index.php?show_example=71 ||55 || Posted by || jcc7 ||56 || Date/Time || Mon May 3, 2004 12:20 am ||