home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / grs / g / mid < prev    next >
Encoding:
Text File  |  1991-03-28  |  1.1 KB  |  59 lines

  1. write(mid("Hello",3,2),"\n");
  2.  
  3. integer i;
  4. string s;
  5.  
  6. i:=1;
  7. s:="Hello";
  8.  
  9. loop
  10.    exiton(i>len(s));
  11.    write(i," = ",mid(s,1,i),"\n");
  12.    i := i+1;
  13. endloop;
  14.  
  15. string function reverse( string s )
  16. {
  17. string result;
  18.  
  19. if s="" then
  20.   return("");
  21. else
  22.   result := reverse(mid(s,len(s)-1,2))+mid(s,1,1);
  23.   return(result);
  24. endif;
  25. };
  26.  
  27. s := "MC SteeveeEye";
  28. write("Reverse of ",s," is ",reverse(s),"\n");
  29.  
  30. integer function pal( string s1,s2 )
  31. {
  32.    s1 := reverse(s1);
  33.    if s1=s2 then
  34.       return(true);
  35.    else
  36.       return(false);
  37.    endif;
  38. };
  39.  
  40. if pal("Hello","olleH") then
  41.    write("Hurrah!\n");
  42. else
  43.    write("Should not get here!\n");
  44. endif;
  45.  
  46. (* now for the known problems -
  47. first a mid which starts just after a \ *)
  48.  
  49. write(mid("I\tam\tfive\n",5,1),"\n");  (* did not work with 2 instead of 1 *)
  50. write(mid("I\tam\tfive\n",5,3),"\n");
  51.  
  52. (* and strings which end in '\' will probably cock it up *)
  53. (* oh, but hang on - why did I get symbol error at 'n' line 54 (now 55) ?*)
  54. write(len("I\tam\tfive\n"),"\n");
  55. write(len("I\tam\tfive\\"),"\n");
  56.  
  57. (* OH WOW! does it really reject a single backslash?!!? *)
  58.  
  59.