case insensitive strfind?

64 vues (au cours des 30 derniers jours)
New
New le 24 Juil 2011
Commenté : Tord Bjørnevaagen le 11 Août 2017
I have a matrix in which there are about 100,000 sentences that I want to scan for the existence of certain words (True/false). For previous scans, searching for one exact word, I used the strfind. Nevertheless, now I have a list of 18 words which might be written in lower or upper cases in the sequences. The strcmpi which could be useful in this case only returns positive if the whole sentence consist of the word... Is there another function I missed?
Thank you

Réponse acceptée

Titus Edelhofer
Titus Edelhofer le 24 Juil 2011
Hi,
one simple method would be to use lower on both the sentences and the words you are using ...
Titus
  1 commentaire
Tord Bjørnevaagen
Tord Bjørnevaagen le 11 Août 2017
I just used this solution, thanks!
strfind(lower(bigText),lower(keyword))

Connectez-vous pour commenter.

Plus de réponses (2)

Fangjun Jiang
Fangjun Jiang le 24 Juil 2011
use regexpi
  1 commentaire
Turner
Turner le 20 Août 2013
takes 10 times longer than lower/upper followed by strfind() in my benchmark

Connectez-vous pour commenter.


Bjorn Gustavsson
Bjorn Gustavsson le 24 Juil 2011
Use: strcmpi
  2 commentaires
Walter Roberson
Walter Roberson le 25 Juil 2011
strcmpi() is not suitable for substring searches. See http://www.mathworks.com/help/techdoc/ref/strcmpi.html about what it _does_ do.
Bjorn Gustavsson
Bjorn Gustavsson le 25 Juil 2011
I misread the original poster's strfind as strcmp...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by