1

I Am using the npm package kafka-node version 3.0.1.

However, am receiving junk characters in the message -

""M`@$�q��1��N$907959dc-30e9-4e5c-af44-09a4f9062fe1�{"header":{"eventName":"myevent","producer"�'INE",DETECTED"}}"

Any help is appreciated.

Vivek
  • 61
  • 1
  • 8

1 Answers1

1

To remove "junk" characters (unicode unprintable characters) just use replace.

const str = "M`@$�q��1��N$907959dc-30e9-4e5c-af44-09a4f9062fe1�";
const res = str.replace(/�/g, "");
console.log(res);

You could alternatively check the character code using filter and join.

const str = "M`@$�q��1��N$907959dc-30e9-4e5c-af44-09a4f9062fe1�";
const res = [...str].filter(e => e.charCodeAt(0) != 65533).join("");
console.log(res);
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
  • Thanks Jack for your reply. This is quick fix using javascript. However, am trying to nail down the root cause. – Vivek Jun 18 '19 at 05:52