How to handle strings containing greek letters in the code

21 views (last 30 days)
Hi, in my code I need to "spellcheck" a string in an object to insure a uniform format. I use regexprep for this. One such change needed is to change the greek letters 'α' and 'β' to 'a' and 'b' respectively.
It appears that the command window and actual code handle these letters differently and I need a way to use greek letters in the regexprep.
classdef myObject < handle
function obj = myObject(input)
obj.text = input;
function spellcheck(obj)
obj.text = regexprep(obj.text,'β','b');
For example: objText = myObject('testβtest')
returns 'testβtest'
The greek letters in the code are changed to '?' but work fine in the command window.
For example: regexprep('testβtest','β','b')
returns 'testbtest'
Is there a workaround to this problem? It must be relatively efficient, I'm sure opening a file containing the greek letters and assigning them to variables would work but that would slow down the code too much.
Thanks for the help,
Zachary Klamer
Zachary Klamer on 6 Jan 2017
It works differently depending on if it is done in the command window or in the code. In the command window it works fine (example 2) but in the code it does not work (example 1).

Sign in to comment.

Accepted Answer

stewpend0us on 26 Jun 2019
if you type double('β') in the command line it will return 946.
In your code instead of using 'β' use char(946).
  1 Comment
Zachary Klamer
Zachary Klamer on 26 Jun 2019
I ended up getting around it with: native2unicode([206,178],'UTF-8')
But this is much more straightforward. Its silly that this is even a problem but this fixes it.

Sign in to comment.

More Answers (0)


Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!