G2A Many GEOs
SHARE
TWEET

String Manipulator 1

RGeorgiev97 Apr 1st, 2020 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $string = readline();
  3. $input = readline();
  4. while ($input!=='End'){
  5.     $args = explode(" ", $input);
  6.     $command = $args[0];
  7.     switch ($command){
  8.         case 'Translate':
  9.             $char = $args[1];
  10.             $replacement = $args[2];
  11.             $string = str_replace($char,$replacement,$string);
  12.             echo $string .PHP_EOL;
  13.             break;
  14.  
  15.         case 'Includes':
  16.             $subString = $args[1];
  17.             str_replace($subString,'',$string,$count);
  18.             if ($count>0){
  19.                 echo 'True' .PHP_EOL;
  20.             } else{
  21.                 echo 'False' .PHP_EOL;
  22.             }
  23.             break;
  24.  
  25.         case 'Start':
  26.             $subString = $args[1];
  27.             if (strpos($string,$subString)==0){
  28.                 echo 'True' .PHP_EOL;
  29.             }
  30.             else{
  31.                 echo 'False' .PHP_EOL;
  32.             }
  33.             break;
  34.  
  35.         case 'Lowercase':
  36.             $string = strtolower($string);
  37.             echo $string .PHP_EOL;
  38.             break;
  39.  
  40.         case 'FindIndex':
  41.             $char = $args[1];
  42.             $lastIndex= strrpos($string,$char);
  43.             echo $lastIndex .PHP_EOL;
  44.             break;
  45.  
  46.         case 'Remove':
  47.             $startIndex = $args[1];
  48.             $count = $args[2];
  49.             $currentString = '';
  50.             for($i = $startIndex; $i < $startIndex+$count; $i++) {
  51.                 $currentString .= $string[$i];
  52.             }
  53.             $string = str_replace($currentString,'',$string);
  54.             echo $string .PHP_EOL;
  55.             break;
  56.     }
  57.  
  58.     $input=readline();
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top