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

  1. // %PARAMETERS = "CH12LIST C:\UT2004"
  2. //Identifies the package
  3. //CH12_03LIST.uc
  4. //-
  5. class CH12_03LIST extends Commandlet;
  6. function int Main(string Args)
  7. {
  8.   //#1
  9.   local int  iFinding, iCount;
  10.   local string szLines, szReturn, szAltered,
  11.                szFirst, szSource ;
  12.  
  13.   szLines = "The intellect of man is forced to choose";
  14.   szLines $= Chr(10);
  15.   szLines $= " Perfection of the life, or of the work";
  16.   szSource = "W. B. Yeats, 'The Choice'";
  17.   szReturn = "";
  18.   szFirst  = "The intellect of man is forced to choose";
  19.   szAltered = "";
  20.   iCount = 0;
  21.  
  22.   log("*************");
  23.   log(Chr(10) @ " CH12_03LIST Comparing strings");
  24.  
  25.   //#2
  26.   log(Chr(10) @ szLines @ Chr(10) @ "         --" $ szSource);
  27.  
  28.   //   Preliminary  --- create an alternative string for comparison
  29.   //   Replace a word and use case
  30.   szReturn = Repl(szFirst, "intellect", "mind", true);
  31.   log(" A - Using Repl to change the word");
  32.   log("     Before ------- ------- " @ Chr(10) @ "    " @ szFirst);
  33.   log("     After  ------- ------- " @ Chr(10) @ "    " @ szReturn);
  34.  
  35.  
  36.   //#3
  37.   //Compare the two stings
  38.   log(" B  - Use of StrCmp");
  39.   iFinding =  StrCmp(szFirst, szReturn, 0, true);
  40.   if(iFinding == 0){
  41.      log ("      Strings before and after changes " @ Chr(10)
  42.         @ "      in A are not the same");
  43.   }
  44.  
  45.  
  46.   //#4
  47.   log( Chr(10));
  48.   log(" C  - Primary and secondary strings and the index");
  49.   iCount = InStr(szFirst, "is");
  50.   log("      Position of 'intellect' in the strings: " @ iCount );
  51.   szAltered = Left(szFirst, iCount);
  52.   szReturn = "";
  53.   szFirst = "";
  54.  
  55.   szFirst = szAltered;
  56.   szFirst $= szAltered;
  57.   szReturn = szAltered;
  58.  
  59.   log("      szFirst  ------- ------- " @ Chr(10) @ "    " @  szFirst);
  60.   log("      szReturn ------- ------- " @ Chr(10) @ "    " @  szReturn);
  61.  
  62.   iCount = Len(szAltered);
  63.  
  64.   log("      A. Position to start the comparison: " @ iCount);
  65.   iFinding =  StrCmp(szFirst, szReturn, iCount, true);
  66.   if(iFinding == 0){
  67.     log ("     Finding A: String zsFirst contains string szReturn;" @ Chr(10)
  68.        $ "     the capitalization is the same. ");
  69.   }
  70.   //A literal approach
  71.   log("      B. Position to start the comparison: " @ iCount);
  72.   iFinding =  StrCmp("The intellect of man The intelxect of man",
  73.                       "The intellect of man aber ", iCount, true);
  74.   if(iFinding == 0){
  75.     log ("     Finding B: String zsFirst contains string szReturn;" @ Chr(10)
  76.        $ "     the capitalization is the same. ");
  77.   }
  78.  
  79.  
  80.   return 0;
  81. }
  82.