I'm wondering if there's a way, while iterating through a string with a for loop, to remove a portion of the string and do something else with it.
Basically, I want to start with one string "first portion|middle|,end" and end with two strings. The "buffer" variable should contain "first portion,end" and the second string should contain "|middle|"
word = "first portion|middle|,end"
buffer = ''
for i in word:
if i == '|':
# Loop in here until another pipeline is found while saving each character
else:
buffer += i
I already have a program that parses the original string and organizes it so ideally I just want to have an if statement in the for loop that will remove anything between pipelines and save it. If this isn't possible I will rewrite the program to allow me too do this.