home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh12 / CH12LIST / Classes / CH12_01LIST.uc next >
Encoding:
Text File  |  2006-02-03  |  2.2 KB  |  74 lines

  1. // %PARAMETERS = "CH12LIST C:\UT2004"
  2. //Identifies the package
  3. //CH12_01LIST.uc
  4.  
  5. class CH12_01LIST extends Commandlet;
  6. function int Main(string Args)
  7. {
  8.   //#1
  9.   local int  iLocation;
  10.   local string szLines, szSearch, szReturn,
  11.                szFirst, szSecond, szSource ;
  12.  
  13.   szLines = "Sighs for folly said and done";
  14.   szLines $= Chr(10);
  15.   szLines $= " Twist our narrow days";
  16.   szSearch = "our";
  17.   szSource = "W. H. Auden, 'Twelve Songs'";
  18.   szReturn = "";
  19.   szFirst  = "";
  20.   szSecond = "";
  21.  
  22.   log("*************");
  23.   log(Chr(10) @ " CH112_01LIST String functions" @ Chr(10));
  24.  
  25.   //#2
  26.   log(Chr(10) @ szLines @ Chr(10) @ "         --" $ szSource);
  27.  
  28.   log(" A - Length of the string " @ Len(szLines));
  29.   //#Search a string using the InStr() function
  30.   iLocation = InStr(szLines , szSearch);
  31.   log(" B - String '" $ szSearch $ "' found at index "
  32.                                    @ iLocation);
  33.  
  34.  
  35.   //#3
  36.   //From the beginning of the source sting to the start
  37.   //of the search word
  38.   szReturn = Left(szLines, iLocation);
  39.   log(" C - Left from start of '" $ szSearch $ "': "
  40.                                    @ Chr(10) @ szReturn);
  41.   szReturn = "";
  42.   //Subtract starting index of search term from the length
  43.   //Gives you the remainder of the string
  44.   szReturn = Right(szLines, Len(szLines) - iLocation);
  45.   log(" D - Right from start of '" $ szSearch $ "': "
  46.                                    @ Chr(10) @ szReturn);
  47.  
  48.   //#4
  49.   //Break the string at the new line character
  50.   Divide(szLines, chr(10), szFirst, szSecond);
  51.   log(" Divide at the new line ");
  52.   log(" E - First part: " @ Chr(10)  @ szFirst);
  53.   log(" E - Second part: " @ Chr(10) @ szSecond);
  54.  
  55.   //#5
  56.   //Change to all lower case letters
  57.   szFirst = Locs(szFirst);
  58.   log(" F - First part in lower case: "
  59.                                     @ Chr(10) @ szFirst);
  60.   //Change to all capital letters
  61.   szSecond   = Caps(szSecond);
  62.   log(" G - First part: " @ Chr(10) @  szSecond);
  63.  
  64.   //#6
  65.    szReturn = "";
  66.   //Subtract starting index of search term from the length
  67.   //Gives you the remainder of the string
  68.   szReturn = Mid(szLines, iLocation);
  69.   log(" H - Mid from start of " $ iLocation $ ": "
  70.                                    @ Chr(10) @ szReturn);
  71.  
  72.   return 0;
  73. }
  74.