Closed crs38c28 closed 5 years ago
I'm using this function to parse chat message.
Actual behaviour:
`Kappa 😮 Kappa`
Expected behaviour:
--
The main reason is because the emoji's length. in user object :
'emotes': { '25': [ '0-4' ,'8-12' ] }
After
var splitText = text.split('');
It will become
(14) ["K", "a", "p", "p", "a", " ", "�", "�", " ", "K", "a", "p", "p", "a"] [ '0-4' ] = "Kappa" [ '8-12'] = " Kapp"
So it will replace wrong words.
use Array.from instead of split can fix this.
var splitText = Array.from(text);
Result :
(13) ["K", "a", "p", "p", "a", " ", "😮", " ", "K", "a", "p", "p", "a"] [ '0-4' ] = "Kappa" [ '8-12'] = "Kappa"
Neat. I don't think we had Array.from back then, but that seems like a nice simple solution.
Array.from
I'm using this function to parse chat message.
Actual behaviour:
Expected behaviour:
--
The main reason is because the emoji's length. in user object :
After
It will become
So it will replace wrong words.
--
use Array.from instead of split can fix this.
Result :