Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of SplitAndSplitLinesExample

Show
Ignore:
Author:
jcc7 (IP: 68.97.93.38)
Timestamp:
11/21/05 04:38:54 (18 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SplitAndSplitLinesExample

    v0 v1  
     1= String usage: split and splitlines = 
     2 
     3''Part of'' StandardLibraryCategory 
     4 
     5 
     6== Description == 
     7 
     8Exercises std.string.splitlines and std.string.split.  
     9(Note: has simulatedFile to be 'self-contained'. Use commented out lines for real file, assumed to be named tutorial.d) 
     10 
     11 
     12== Example == 
     13 
     14{{{ 
     15#!d 
     16import std.stdio; 
     17import std.string; 
     18 
     19//import std.file; 
     20 
     21//char[] actualFile = cast(char[])std.file.read("tutorial.d"); 
     22 
     23const char[] simulatedFile =  
     24  "Line 1 one\n" 
     25  "Line 2 two\n" 
     26  "Line 3 three"; 
     27 
     28void main () 
     29{ 
     30  char[][] allLines = splitlines(simulatedFile); 
     31 
     32  foreach (char[] curLine; allLines) { 
     33    writef(curLine, " = "); 
     34    char[][] allWordsInCurLine = split(curLine); 
     35    foreach (char[] curWord; allWordsInCurLine) { 
     36      writef('[', curWord, ']', ' '); 
     37    } 
     38    writefln(); 
     39  } 
     40} 
     41}}} 
     42 
     43== Source == 
     44 
     45|| Link || http://www.dsource.org/tutorials/index.php?show_example=120 || 
     46|| Posted by || Lynn || 
     47|| Date/Time || Fri Sep 24, 2004 3:15 pm ||