Home > Software design >  converting the letter ي with ی
converting the letter ي with ی

Time:11-16

is there any way to convert Arabic ي to the Persian ي in React JS? I have an array of data in Persian language which contains the Arabic ي . and that's because of bad language support for Persian.

if I want to make a search functionality, I must enter ي instead ی and I can't force people to do this. how can I solve it?

there's a similar question here but with C#.

for example :

const items = ["ماشین","هواپیما","موبایل","کامپیوتر"]
const searchedItem = items.filter(item=>item==="ماشین")

in order to search "ماشین" (car) I need to type it with ي . it won't work with regular ی

CodePudding user response:

const items = ["ماشین","هواپیما","موبایل","کامپیوتر"]
const searchedItem = items.filter(item=>item==="ماشین" || item === 'ماشین'.replace(/ي/g, 'ی'))
console.log(searchedItem)

CodePudding user response:

If you can, fix the data instead of putting a character replacement on the frontend.

Otherwise, if you have more than ten or unknown phrases with that character, and especially if you want fuzzy search... you're going to have to scan every character for each datum. Since strings are immutable, you could make a character array and then return the new filtered character instead.

  • Related