Doxygen Source Code Documentation
FindChar.m
Go to the documentation of this file.00001 function [err,Loc] = FindChar (C, cfnd)
00002 %
00003 % [err,Loc] = FindChar (C, cfnd)
00004 %
00005 %Purpose:
00006 % find certain characters in an array of characters, or a string
00007 %
00008 %
00009 %Input Parameters:
00010 % C : an array of characters or a string
00011 % cfnd : the character you'r looking for like 'f'
00012 % pass the following for special characters
00013 % 'NewLine', 'Tab', 'Space', 'Comma'
00014 %
00015 %Output Parameters:
00016 % err : 0 No Problem
00017 % : 1 Mucho Problems
00018 % Loc : a vector of the location in C containing cfnd
00019 % ie any element Loc of C is cnfd. C(Loc) = cfnd
00020 %
00021 %
00022 %More Info :
00023 %
00024 % example :
00025 % ks2 = sprintf('d, v h\t\nc c , c d\n vf');
00026 % [err, Loc] = FindChar(ks2, ',')
00027 % or in the previous case, you could use
00028 % [err, Loc] = FindChar(ks2, 'Comma')
00029 % or
00030 % [err, Loc] = FindChar(ks2, 'Tab')
00031 %
00032 % ks2 could be a whole ascii file or a chunk of one, like
00033 % fid = fopen('thisfile','r'); ks2 = fscanf(fid,'%c',100); fclose (fid);
00034 % the previous line reads the 1st 100 characters
00035 % carefull, if you use
00036 % ks2 = fscanf(fid,'%s',100);
00037 % you'll read the first 100 strings (space, tab and newline delimited)
00038 %
00039 % see also
00040 % SkipMatlabHelp
00041 % PurgeComments
00042 % NextString
00043 %
00044 % Author : Ziad Saad
00045 % Date : Sat Mar 27 13:42:26 CST 1999
00046
00047
00048 %Define the function name for easy referencing
00049 FuncName = 'FindChar';
00050
00051 %Debug Flag
00052 DBG = 1;
00053
00054 %initailize return variables
00055 err = 1;
00056 Loc = [];
00057
00058 switch cfnd,
00059 %to find the ascii number for new characters, try
00060 % ks2 = sprintf('d, v h\t\n');
00061 % ks2num = str2num(sprintf('%d\n',ks2))
00062 case 'NewLine',
00063 cfndInt = 10;
00064 case '\n',
00065 cfndInt = 10;
00066 case 'Tab',
00067 cfndInt = 9;
00068 case '\t',
00069 cfndInt = 9;
00070 case 'Space',
00071 cfndInt = 32;
00072 case 'Comma',
00073 cfndInt = 44;
00074 otherwise,
00075 if (length(cfnd) > 1),
00076 err = ErrEval(FuncName,'Err_Special Character not supported');
00077 return;
00078 else
00079 cfndInt = str2num(sprintf('%d\n',cfnd));
00080 end
00081 end
00082
00083 %Now find such characters
00084
00085 Loc = find (C == cfndInt(1));
00086
00087 %that's it, get back
00088
00089
00090 err = 0;
00091 return;
00092