Advertisement
exDotaPro

string_manipulator_2

Aug 5th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. def replace_char(change_from, change_to, my_string):
  2.     return my_string.replace(change_from, change_to)
  3.  
  4.  
  5. def include_substring(substring, my_string):
  6.     return substring in my_string
  7.  
  8.  
  9. def ends_with_substring(substring, my_string):
  10.     return my_string.endswith(substring)
  11.  
  12.  
  13. def upper_case(my_string):
  14.     return my_string.upper()
  15.  
  16.  
  17. def find_first_idx(ch, my_string):
  18.     return my_string.index(ch)
  19.  
  20.  
  21. def cut_part_of_string(start, end, my_string):
  22.     return my_string[start:start + end]
  23.  
  24.  
  25. string = input()
  26.  
  27. while True:
  28.     line = input().split()
  29.     command = line[0]
  30.  
  31.     if command == 'Done':
  32.         break
  33.  
  34.     if command == 'Change':
  35.         string = replace_char(line[1], line[2], string)
  36.         print(string)
  37.     elif command == 'Includes':
  38.         print(include_substring(line[1], string))
  39.     elif command == 'End':
  40.         print(ends_with_substring(line[1], string))
  41.     elif command == 'Uppercase':
  42.         string = upper_case(string)
  43.         print(string)
  44.     elif command == 'FindIndex':
  45.         print(find_first_idx(line[1], string))
  46.     elif command == 'Cut':
  47.         string = cut_part_of_string(int(line[1]), int(line[2]), string)
  48.         print(string)
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement