1function [err,Loc] = FindChar (C, cfnd)
2%
3%   [err,Loc] = FindChar (C, cfnd)
4%
5%Purpose:
6%   find certain characters in an array of characters, or a string
7%
8%
9%Input Parameters:
10%   C : an array of characters or a string
11%   cfnd : the character you'r looking for like 'f'
12%   	pass the following for special characters
13%		'NewLine', 'Tab', 'Space', 'Comma'
14%
15%Output Parameters:
16%   err : 0 No Problem
17%       : 1 Mucho Problems
18%   Loc : a vector of the location in C containing cfnd
19%      ie any element Loc of C is cnfd. C(Loc) = cfnd
20%
21%
22%More Info :
23%
24%   example :
25%	ks2 = sprintf('d, v h\t\nc c , c d\n vf');
26%	[err, Loc] = FindChar(ks2, ',')
27% or in the previous case, you could use
28%  [err, Loc] = FindChar(ks2, 'Comma')
29% or
30%  [err, Loc] = FindChar(ks2, 'Tab')
31%
32% ks2 could be a whole ascii file or a chunk of one, like
33% fid = fopen('thisfile','r'); ks2 = fscanf(fid,'%c',100); fclose (fid);
34% the previous line reads the 1st 100 characters
35% carefull, if you use
36% ks2 = fscanf(fid,'%s',100);
37% you'll read the first 100 strings (space, tab and newline delimited)
38%
39% see also
40%  SkipMatlabHelp
41%  PurgeComments
42%	NextString
43%
44%     Author : Ziad Saad
45%     Date : Sat Mar 27 13:42:26 CST 1999
46
47
48%Define the function name for easy referencing
49FuncName = 'FindChar';
50
51%Debug Flag
52DBG = 1;
53
54%initailize return variables
55err = 1;
56Loc = [];
57
58switch cfnd,
59	%to find the ascii number for new characters, try
60	%	ks2 = sprintf('d, v h\t\n');
61	%	ks2num = str2num(sprintf('%d\n',ks2))
62	case 'NewLine',
63		cfndInt = 10;
64	case '\n',
65		cfndInt = 10;
66	case 'Tab',
67		cfndInt = 9;
68	case '\t',
69		cfndInt = 9;
70	case 'Space',
71		cfndInt = 32;
72	case 'Comma',
73		cfndInt = 44;
74	otherwise,
75		if (length(cfnd) > 1),
76			err = ErrEval(FuncName,'Err_Special Character not supported');
77			return;
78		else
79			cfndInt = str2num(sprintf('%d\n',cfnd));
80		end
81end
82
83%Now find such characters
84
85	Loc = find (C == cfndInt(1));
86
87%that's it, get back
88
89
90err = 0;
91return;
92
93