0

I have to intercept all emojs inside a string

input   "bla bla   bla  "
desired output  "bla bla <b></b>  bla  <b></b>"

my code is

string input = "bla bla   bla  ";
var output1 = Regex.Replace(input, @"[\p{C}]|[\p{So}]|[\u20E3]+", "<b>$1</b>");
var output2 = Regex.Replace(input, @"[\p{C}]|[\p{So}]|[\u20E3]+", "emj");


output 1:
bla bla <b>$1</b><b>$1</b>  bla  <b>$1</b><b>$1</b>

output2
bla bla emjemj  bla  emjemj
Fede
  • 9
  • 4
  • I would check this question https://stackoverflow.com/questions/30757193/find-out-if-character-in-string-is-emoji – Özgür Güzeldereli Feb 06 '20 at 19:23
  • You might want to be more explicit on what you are trying to achieve. My first read of you "question" (note, there is no question mark in your question) was to say to myself "Uh, so..." – Flydog57 Feb 06 '20 at 19:23
  • I would like to insert an html tag around every emoji found desired output "bla bla bla " – Fede Feb 06 '20 at 19:52
  • I don't think the *answered question* answers your question (from my understanding - that's why you need to be explicit). I got things working by using the non-static version of `Regex.Replace` and by changing your pattern somewhat: `const string emojiPattern = @"(\p{C}|\p{So}|\u20E3)+"; var regex = new Regex(emojiPattern); var replaced = regex.Replace(input, "$1");` – Flydog57 Feb 06 '20 at 20:12
  • Edit your question to ask want you really want. The duped question answers what you "ask" in the title. Change the title, be explicit (and ask a real question) in the body. If the question gets reopened, send a comment to me and I'll expand on my comment above with a real answer. Otherwise, my comment above *should* help you out. – Flydog57 Feb 07 '20 at 01:05

0 Answers0