I have a Python code that read text files and allow the user to enter a searched word where the system do the matching task.
what i want is to be able to find the entered word if exist in the text no matter how its written (upper, lower, capitalized), without using Regular expression.
i know that the code i wrote is not correct because the output is the hall text splited in a list.
where the result must be:
self.varStr = user-input repeated as many as it exist in the text in any mentioned case.
example :
- user-input = charl
- existing word: Charles,Charles
so what i did is :
textString contains the hall text.
Les hiboux Charles Baudelaire
Cycle 3 *
POESIE
Sous les ifs noirs qui les abritent Les hiboux se tiennent rangés Ainsi que des dieux étrangers Dardant leur œil rouge. Ils méditent.
Sans remuer ils se tiendront Jusqu'à l'heure mélancolique Où, poussant le soleil oblique, Les ténèbres s'établiront.
Leur attitude au sage enseigne Qu'il faut en ce monde qu'il craigne Le tumulte et le mouvement ;
L'homme ivre d'une ombre qui passe Porte toujours le châtiment D'avoir voulu changer de place.
Les Fleurs du Mal 1857
Charles Pierre Baudelaire (1821 – 1867) est un poète français.
code:
x=self.lineEditSearch.text()
print(x)
textString=self.ReadingFileContent(Item)
#self.varStr =[c for c in textString if c.islower() or c.isupper() or c.capitalize()]
self.varStr =[x for x in textString.split(" ") if x.islower() or x.isupper() or x.capitalize()]
print(self.varStr)