String comparison: Difference between revisions
Content added Content deleted
m (added related tasks.) |
|||
Line 2,295: | Line 2,295: | ||
Comparing for order (case sensitive): mathematica comes before Mathematica |
Comparing for order (case sensitive): mathematica comes before Mathematica |
||
Comparing for equality (case insensitive): mathematica and Mathematica ARE equal</pre> |
Comparing for equality (case insensitive): mathematica and Mathematica ARE equal</pre> |
||
=={{header|MATLAB}} / {{header|Octave}}== |
|||
<lang Matlab> |
|||
a="BALL"; |
|||
b="BELL"; |
|||
if a==b, disp('The strings are equal'); end; |
|||
if strcmp(a,b), disp('The strings are equal'); end; |
|||
if a~=b, disp('The strings are not equal'); end; |
|||
if ~strcmp(a,b), disp('The strings are not equal'); end; |
|||
if a > b, disp('The first string is lexically after than the second'); end; |
|||
if a < b, disp('The first string is lexically before than the second'); end; |
|||
if a >= b, disp('The first string is not lexically before than the second'); end; |
|||
if a <= b, disp('The first string is not lexically after than the second'); end; |
|||
% to make a case insensitive comparison convert both strings to the same lettercase: |
|||
a="BALL"; |
|||
b="ball"; |
|||
if strcmpi(a,b), disp('The first and second string are the same disregarding letter case'); end; |
|||
if lower(a)==lower(b), disp('The first and second string are the same disregarding letter case'); end; |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
The strings are not equal |
|||
The strings are not equal |
|||
The first string is lexically before than the second |
|||
The first string is not lexically after than the second |
|||
The first and second string are the same disregarding letter case |
|||
The first and second string are the same disregarding letter case |
|||
</pre> |
|||
=={{header|MiniScript}}== |
=={{header|MiniScript}}== |