3

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;
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • Hmm, interesting. Regex is the only thing that crosses my mind, have you tried with that? – Mark Jan 28 '21 at 00:06
  • 1
    A regex may get complex, as Emojis are scattered throughout the Unicode character space (see the latest [emoji-data.txt](https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt) and [full-emoji-list.html](http://www.unicode.org/emoji/charts/full-emoji-list.html)), and can have many different combinations of combining characters attached to them to modify their appearance (skin color, gender, etc). Does the string in question ever contain any non-ASCII characters besides Emojis? If not, it would be easier to simply remove all non-ASCII characters, than removing Emojis specifically. – Remy Lebeau Jan 28 '21 at 00:22
  • 2
    Here is a similar question with a regex solution that catches all defined emojis: [Detecting *all* emojis](https://stackoverflow.com/q/46905176/576719) – LU RD Jan 28 '21 at 06:56
  • 1
    Your code contradicts your question/expectations: it also removes a whitespace. – AmigoJack Jan 28 '21 at 09:01
  • So far the answer to this question seems to make the job : https://stackoverflow.com/questions/5650532/delphi-strip-out-all-non-standard-text-characers-from-string – delphirules Jan 28 '21 at 11:05
  • @delphirules: The accepted answer? It only works for basic Latin. For instance, if I would try it on `Fåglar är så vackra djur! ` I would get very sad. And even if you only write in English, you will get disappointed: `Try to compute ∫sin(x)dx from 0 to π. Without !` Not to mention `️ Temperature: −20 °C`. – Andreas Rejbrand Jan 28 '21 at 13:12
  • @delphirules why not linking to "the" answer you mean? Ambiguity is so very often your partner... – AmigoJack Jan 28 '21 at 13:57
  • @AndreasRejbrand You are correct, it worked for me because i'm only using portuguese / english languages – delphirules Jan 30 '21 at 16:22
  • @AmigoJack Well i meant the accepted answer of the question... kind of obvious, isn't ? :-) – delphirules Jan 30 '21 at 16:23

0 Answers0