Effacer les filtres
Effacer les filtres

Using or with strfind

15 vues (au cours des 30 derniers jours)
v k
v k le 12 Fév 2021
Commenté : KSSV le 12 Fév 2021
Hello,
I have two patterns p1 (or) p2, to be found within a single string, str. The objective is to get the position if either of those two patterns is found. But the following doesn't seem to work:
position=strfind(str,p1 || p2)
How to modify this statement to get the result?
Thanks.

Réponses (1)

KSSV
KSSV le 12 Fév 2021
position1 = strfind(str,p1) ;
position2 = strfind(str,p2) ;
OR
position = strfind(str,[p1, p2]) ;
  3 commentaires
v k
v k le 12 Fév 2021
The objective is to extract out the items: item1 and item2.
KSSV
KSSV le 12 Fév 2021
position1 = strfind(str,p1) ;
position2 = strfind(str,p2) ;

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