How to check if particular string exists within a file path (string)

4 vues (au cours des 30 derniers jours)
Prashant Kashid
Prashant Kashid le 3 Fév 2013
Hi, I am stuck up with a simple query wherein I want to check if particular string exits in a given string. i.e. If I am using input image from following file path C:\New Folder\Level1\Image1.tiff Now I want to check if a string "Level1" exists in a given file path name. I want to know only its existence & not its length, position or occurrence. Simply in the form of true or false (o or 1). Can someone please help me with this. Thanks in advance for your help!

Réponse acceptée

Image Analyst
Image Analyst le 3 Fév 2013
Modifié(e) : Image Analyst le 3 Fév 2013
Look at these examples, and pick whichever one of the methods suits you best:
s = 'C:\New Folder\Level1\Image1.tiff'
template = 'Level1' % Cases match
foundIt = any(ismember(s, template))
index = strfind(s, template)
foundIt = ~isempty(index)
template = 'level1' % Case mismatch.
index = strfind(s, template)
foundIt = ~isempty(index)
template = 'level1' % Case mismatch.
index = strfind(upper(s), upper(template))
foundIt = ~isempty(index)
  4 commentaires
Image Analyst
Image Analyst le 3 Fév 2013
And the semicolon at the end of an "if" statement is ignored.
Prashant Kashid
Prashant Kashid le 3 Fév 2013
Thanks a million! I missed that one in a haste!

Connectez-vous pour commenter.

Plus de réponses (0)

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