1+ def clearStrech (txt : str , Start : str , End = None ):
2+ """
3+ :param txt: (str) Text to remove the strech
4+ :param Start: (str) Initial stretch of removal
5+ :param End: (str) Final strech of removal
6+ :return: (str) Text Processed
7+
8+ Example to use:
9+ Your text is: txt = str(' "<Conserpts>": Text:Him rendered(or released) may attended concerns jennings reserved now')
10+ You just want the text, or you need to remove it: "<Conserpts>": Text:
11+ And you also don't want what's in brackets
12+ So call this method:
13+ txt = clearStreches(txt,' "<Con','Text:')
14+ txt = clearStreches(txt,'(',')')
15+ print(txt)
16+ # 'Him rendered may attended concerns jennings reserved now'
17+ now your text is clear of unwanted characters
18+ """
19+ # always included the space and add an extra parameter. Example: (-/+.!#%&*弻)
20+ IncludeParam = (" ," , " ." , " :" )
21+
22+ if (End is None ):
23+ End = str (Start )
24+ while txt .find (End ) != - 1 :
25+ pri = txt .find (Start )
26+ seg = txt .find (End , pri + 1 )
27+ if (pri == - 1 or txt .find (Start ) == txt .rfind (End )):
28+ break
29+ for param in IncludeParam :
30+ if (txt [seg + 1 ] in param and txt [pri - 1 ] in param [0 ]):
31+ try :
32+ if (txt [seg + 1 ] in param [1 ]):
33+ txt = txt [:pri - 1 ] + txt [seg + len (End ):]
34+ break
35+ else :
36+ if (txt [seg + 2 ] == param [0 ]):
37+ seg += 1
38+ txt = txt [:pri ] + txt [seg + len (End ) + 1 :]
39+ break
40+ except :
41+ # necessary to pass to continue the for
42+ pass
43+ if (param == IncludeParam [len (IncludeParam ) - 1 ]):
44+ txt = txt [:pri ] + txt [seg + len (End ):]
45+
46+ return txt
47+
48+
49+ """
50+ # Example of use: remove the "" and execute the code
51+ # from RemoveStreches import clearStrech # utilize this in your code to import
52+ txt = '<wiki>/<div>/<option:en-us>/MainText:Michael Joseph Jackson (August 29, 1958 – June 25, 2009) was an American ' \
53+ 'singer (usa), and dancer. Dubbed the "King of Pop". Its awesome!'
54+ print(txt)
55+ txt = clearStrech(txt, "<wiki>", "MainText:")
56+ txt = clearStrech(txt, "(", ")")
57+ txt = clearStrech(txt, '"', '"')
58+ print(txt)
59+ """
60+
61+
62+ # Credits
63+
64+ """
65+ Any error that the code has / actions to add send an issue on github
66+ GitHub: https://github.com/DinowSauron/RemoveStreches_Python/upload/master
67+
68+ Versions:
69+ -clearStrech: 0.1.2
70+
71+
72+
73+ Creators:
74+ -Luiz Claudio.
75+ """
0 commit comments