home *** CD-ROM | disk | FTP | other *** search
- // %PARAMETERS = "CH12LIST C:\UT2004"
- //Identifies the package
- //CH12_03LIST.uc
- //-
- class CH12_03LIST extends Commandlet;
- function int Main(string Args)
- {
- //#1
- local int iFinding, iCount;
- local string szLines, szReturn, szAltered,
- szFirst, szSource ;
-
- szLines = "The intellect of man is forced to choose";
- szLines $= Chr(10);
- szLines $= " Perfection of the life, or of the work";
- szSource = "W. B. Yeats, 'The Choice'";
- szReturn = "";
- szFirst = "The intellect of man is forced to choose";
- szAltered = "";
- iCount = 0;
-
- log("*************");
- log(Chr(10) @ " CH12_03LIST Comparing strings");
-
- //#2
- log(Chr(10) @ szLines @ Chr(10) @ " --" $ szSource);
-
- // Preliminary --- create an alternative string for comparison
- // Replace a word and use case
- szReturn = Repl(szFirst, "intellect", "mind", true);
- log(" A - Using Repl to change the word");
- log(" Before ------- ------- " @ Chr(10) @ " " @ szFirst);
- log(" After ------- ------- " @ Chr(10) @ " " @ szReturn);
-
-
- //#3
- //Compare the two stings
- log(" B - Use of StrCmp");
- iFinding = StrCmp(szFirst, szReturn, 0, true);
- if(iFinding == 0){
- log (" Strings before and after changes " @ Chr(10)
- @ " in A are not the same");
- }
-
-
- //#4
- log( Chr(10));
- log(" C - Primary and secondary strings and the index");
- iCount = InStr(szFirst, "is");
- log(" Position of 'intellect' in the strings: " @ iCount );
- szAltered = Left(szFirst, iCount);
- szReturn = "";
- szFirst = "";
-
- szFirst = szAltered;
- szFirst $= szAltered;
- szReturn = szAltered;
-
- log(" szFirst ------- ------- " @ Chr(10) @ " " @ szFirst);
- log(" szReturn ------- ------- " @ Chr(10) @ " " @ szReturn);
-
- iCount = Len(szAltered);
-
- log(" A. Position to start the comparison: " @ iCount);
- iFinding = StrCmp(szFirst, szReturn, iCount, true);
- if(iFinding == 0){
- log (" Finding A: String zsFirst contains string szReturn;" @ Chr(10)
- $ " the capitalization is the same. ");
- }
- //A literal approach
- log(" B. Position to start the comparison: " @ iCount);
- iFinding = StrCmp("The intellect of man The intelxect of man",
- "The intellect of man aber ", iCount, true);
- if(iFinding == 0){
- log (" Finding B: String zsFirst contains string szReturn;" @ Chr(10)
- $ " the capitalization is the same. ");
- }
-
-
- return 0;
- }
-