Find all the occurrences of a character in a string

后端 未结 7 626
情深已故
情深已故 2020-12-01 12:02

I am trying to find all the occurences of \"|\" in a string.

def findSectionOffsets(text):
    startingPos = 0
    endPos = len(text)

    for position in te         


        
7条回答
  •  感情败类
    2020-12-01 12:35

    It is easier to use regular expressions here;

    import re
    
    def findSectionOffsets(text):
        for m in re.finditer('\|', text):
            print m.start(0)
    

提交回复
热议问题