-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringTobraille.m
30 lines (24 loc) · 1.11 KB
/
stringTobraille.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function braille = stringTobraille(inputString, BRAILLE_ALPHABET)
% Convert (encode) a string into the Braille alphabet.
% Initialize an empty string to store the encoded Braille
braille = '';
% Replace multiple spaces in the input string with a single space
inputString = regexprep(inputString, ' +', ' ');
% Iterate through the characters in the input string
for i = 1:length(inputString)
% Get the current character from the input string
char = inputString(i);
% Look up the corresponding Braille code for the character in the provided map
brailleChar = BRAILLE_ALPHABET(char);
% Check if a Braille code exists for the character
if isempty(brailleChar)
% If not, append the original character to the Braille string
braille = [braille, char];
else
% If a Braille code exists, append it to the Braille string
braille = [braille, brailleChar];
end
end
% Trim any leading or trailing spaces in the encoded Braille
braille = strtrim(braille);
end