Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the color of specific letter in console

Tags:

matlab

I am forming an specific string using several strcat and displaying it into console. This string contains characters such as: 1,2,3,4,5,6,7,8,9,0,#,*,E and am using fprintf('%s') for this purpose.

For instance:

2E4137E65922#

is a possible outcome of the code.

Is there anyway I could make letter E to stand out in my output? Like making it red?

like image 350
Bababarghi Avatar asked Sep 21 '15 11:09

Bababarghi


2 Answers

Thanks @Dev -iL for this information!

While it seems that cprinf() from my other answer does not work for single characters, if there is a single color that one wants to use, and that color is orange, then this trick used for warning in cprintf can be used:

disp(['this is [' 8 'orange]' 8 ' text'])

Read more at: http://undocumentedmatlab.com/blog/another-command-window-text-color-hack

Thus, your code would look like:

s='2E4137E65922#';
C=strsplit(s,'E');
str=C{1};
for ii=2:size(C,2)
    str=[str ['[' 8 'E]' 8 ]];
    str=[str C{ii}];
end
disp(str);

enter image description here

like image 104
Ander Biguri Avatar answered Nov 13 '22 20:11

Ander Biguri


You can use the HTML tags <strong>, </strong> to type specific letters in bold:

str = '2E4137E65922#'; %// input string
letter = 'E'; %// letter that should be made bold
strBold = regexprep(str, letter, ['<strong>' letter '</strong>']); %// output string
disp(str)
disp(strBold)
like image 5
Luis Mendo Avatar answered Nov 13 '22 19:11

Luis Mendo