0 Replies - 639 Views - Last Post: 05 September 2016 - 04:50 PM

#1 NeoTifa  Icon User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4055
  • View blog
  • Posts: 18,098
  • Joined: 24-September 08

[MATLAB] IsNum, IsAlpha, IsAlphaNum

Posted 05 September 2016 - 04:50 PM

Nothing much, just something small but it's handy. :) Since they're so tiny, I'm putting all 3 in the same snippet. Just do me a favor, if you use it, give me credit (although something so tiny is pretty basic).

IsNum
function [ isnum ] = IsNum ( c )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IsNum - Returns true if char c is a number
%
% Determines whether c is a number or not
% Author: NeoTifa @ dreamincode.net
%
% example: c = '1' -> true/1, c = 'a' -> false/0
%
% args:
% c - char to check
%
% rets:
% isnum - true/1 if c is a number, false/0 otherwise
%
% Assumptions:
% - c is a single character
% - c is ASCII
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

isnum = (c >= '0') && (c <= '9');

end



IsAlpha
function [ isalpha ] = IsAlpha ( c )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IsAlpha - Returns true if char c is an alphabetical letter
%
% Determines whether c is a letter or not
% Author: NeoTifa @ dreamincode.net
%
% example: c = 'a' -> true/1, c = '1' -> false/0
%
% args:
% c - char to check
%
% rets:
% isalpha - true/1 if c is an alpha letter, false/0 otherwise
%
% Assumptions:
% - c is a single character
% - c is ASCII
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

isalpha = ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));

end



IsAlphaNum
function [ isalphanum ] = IsAlphaNum ( c )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IsAlpha - Returns true if char c is an alphanumerical character
%
% Determines whether c is a letter or a number.
% Author: NeoTifa @ dreamincode.net
%
% example: c = 'a' -> true/1, c = '1' -> true/1, c = ',' -> false/0
%
% args:
% c - char to check
%
% rets:
% isalphanum - true/1 if c is an alphanumerical char, false/0 otherwise
%
% Assumptions:
% - c is a single character
% - c is ASCII
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

isalphanum = ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9'));

end


This post has been edited by NeoTifa: 11 September 2016 - 10:47 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1