-2

I'm using Python to get title names for a header in a program. Each title comes like: "OXD/Overview Controls", "OXD/BULK/BULK Details Controls" and more... Currently I am using a value/split() method to remove the "/" returning only "OXD Overview Controls" and "OXD BULK", however I would like to remove the "OXD" and "Controls" portions of the string. Any help is appreciated, my current code is listed below.

if value <> None:
    value = value.split("/")[:2]
    value = ' '.join(value)
else:
    value = ""  
return value.upper()
supanova
  • 13
  • 3
  • Here is your answer: https://stackoverflow.com/questions/37372603/how-to-remove-specific-substrings-from-a-set-of-strings-in-python – DSteman May 25 '21 at 14:54
  • You could try slicing if it is always in the first 5 characters of the string. Or you could try the replace method. str.replace("thing to replace", "replace with this") – Steven Barnard May 25 '21 at 14:54
  • 3
    Does this answer your question? [How to remove specific substrings from a set of strings in Python?](https://stackoverflow.com/questions/37372603/how-to-remove-specific-substrings-from-a-set-of-strings-in-python) – DSteman May 25 '21 at 16:33

1 Answers1

0

@Steven Barnard and @DSteman: Sorry, I wrote something and you both was faster as me. ^^'

You can use the string_variable.replace(search,replace_with) function.

Replace OXD with nothing:

value.replace("OXD","")

Replace / with Space:

value.replace("/"," ")