how to compare a string variable with a string?

10 次查看(过去 30 天)
Hi How to compare string variable with a string?

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-6-18
Read about strcmp
  1 个评论
pricky
pricky 2014-6-18
i have used strcmp but i'm getting a 0 for same string. dirName(k1+2, :) is a variable which dynamically gets the string,now i have to compare the string obtained from dirName(k1+2, :) with the one i have mentioned. ex: if i get dirName(k1+2, :) = abc.mat (dynamically)
strcmp(dirName(k1+2, :),'abc.mat')
but output is being displayed as 0.

请先登录,再进行评论。

更多回答(1 个)

SRI
SRI 2014-6-18
for example
inputData = 'Example';
outputData = strcmp(inputData,'Example');
If outputData = 1 means both the data are equal if 0 means it is not equal
  1 个评论
pricky
pricky 2014-6-18
i have used strcmp but i'm getting a 0 for same string. dirName(k1+2, :) is a variable which dynamically gets the string,now i have to compare the string obtained from dirName(k1+2, :) with the one i have mentioned. ex: if i get dirName(k1+2, :) = abc.mat (dynamically)
strcmp(dirName(k1+2, :),'abc.mat')
but output is being displayed as 0.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by