Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove emojis from a Delphi string

Tags:

delphi

My question is simple as that : if a string has a emoji inside it, how to remove it and return all contents of the string BUT the emojis ?

function removeEmoji(s : string);
begin
// supose s := 'Testing 😀';
// i need to return only 'Testing';
end;
like image 455
delphirules Avatar asked Nov 22 '25 20:11

delphirules


1 Answers

I searched for a long time, found nothing (nice code). Based on the experience, it reached regular expressions.

The task can be put on, I want to have only the necessary symbols in the string:

Below is a template (not fully working code) from a working project (Delphi 10.4)

uses
System.regularexpressions;
Function UpdateinFormorder (IDORDER: String): Integer;
Var
TEMP, Strregexp: String;
REGEX: TREGEX;
Begin
regex.create ('');
// What is allowed in the string utf English, Russian Code page, number and other
strregexp: = '[^A-Za-zА-Яа-я0-9 _ ,, ..?!-@<> "; ::; ()+=/\ |]';
// in TEMP we keep the string cut from extra characters
TEMP: = regex.Replace ('testing 😀', strregexp, '');
end;
like image 164
user30267562 Avatar answered Nov 24 '25 10:11

user30267562



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!