You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
399 B

  1. def cut(instr: str, field_num: int = 0, delimiter: str = "-") -> str:
  2. """
  3. Разделить входную строку `instr` разделительем `delimiter`
  4. и вернуть поле `field_num`.
  5. """
  6. if instr is None:
  7. return ""
  8. parts = str(instr).split(delimiter)
  9. if field_num < len(parts):
  10. return parts[field_num]
  11. else:
  12. return ""