View Single Post
Old 09-05-2021, 04:09 PM   #6
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
You can also use user defined template functions to do one of two things:
  1. Remove non unicode characters as you requested:
    Code:
    def evaluate(self, formatter, kwargs, mi, locals, val):
    	string_encode = val.encode("ascii", "ignore")
    	string_decode = string_encode.decode()
    	return string_decode
    you can use the new function like this:

    Code:
    program:
    	s = 'ᕼ ᗩ ᒪ ᖴ - ᒪ I ᖴ ᗴ';
    	remove_unicode_characters(s)
  2. Make lookup replacement for unicode characters:
    Code:
    def evaluate(self, formatter, kwargs, mi, locals, val):
    	lookup = {
    	    'ᕼ': 'H',
    	    'ᗩ': 'A',
    	    'ᒪ': 'L',
    	    'ᖴ': 'F',
    	    'ᗴ': 'E'
    	}
    	new_string = ''
    	for ch in val:
    	    new_string += lookup.get(ch, ch)
    	return new_string
    You need to expand the lookup dictionary (highlighted in blue) to include any additional unicode characters you want.

    You can use this new function as follows

    Code:
    program:
    	s = 'ᕼ ᗩ ᒪ ᖴ - ᒪ I ᖴ ᗴ';
    	unicode_lookup(s)

Notes
  • To add the new functions described above: preferences > template functions > template functions tab > copy-paste in the program code box and enter the name of the function (highlighted above in green) in the function box.
  • For both functions the argument count should be set to 1.

Last edited by capink; 09-05-2021 at 04:16 PM.
capink is offline   Reply With Quote