-1

I am looking for the best and fastest way to change all of the characters in string in javascript or jquery

for example:

abcdefghijklmnopqrstuvwxyz ==> αв¢∂єƒgнιנкℓмησρqяѕтυνωχуz

or

abcdefghijklmnopqrstuvwxyz ==> åߢÐê£ghïjklmñðþqr§†µvwx¥z

. . .

<textarea>hello world</textarea>

output: нєℓℓσ ωσяℓ∂

Amin
  • 5
  • 3
  • _"javascript or jquery"_ jquery won't help here. To clafiy, jQuery is built using javascript and is a library for manipulating HTML. Also see [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – evolutionxbox Mar 19 '21 at 11:40
  • Please go read [ask]. This site is not a code-writing service, you are supposed to do your own research, and to make an attempt yourself at least. Please do not ask this kind of “what is the best way to do X” questions - because that implies, that you want _us_ to list all possible ways for you to begin with, and that is not our “job” here. – CBroe Mar 19 '21 at 11:47

2 Answers2

0

I think this could be the best (only) solution for your problem

Replace multiple strings with multiple other strings

You have to map manually every character and replace with the character you want :(

Cosimo Chellini
  • 1,560
  • 1
  • 14
  • 20
0

Use an object to have the character by character translation, and then call replace with the callback argument:

tran = {
  "a": "α",
  "b": "в",
  "c": "¢",
  "d": "∂",
  "e": "є",
  "f": "ƒ",
  "g": "g",
  "h": "н",
  "i": "ι",
  "j": "נ",
  "k": "к",
  "l": "ℓ",
  "m": "м",
  "n": "η",
  "o": "σ",
  "p": "ρ",
  "q": "q",
  "r": "я",
  "s": "ѕ",
  "t": "т",
  "u": "υ",
  "v": "ν",
  "w": "ω",
  "x": "χ",
  "y": "у",
  "z": "z"
};

let input = document.querySelector("textarea");
let output = document.querySelector("div");
input.addEventListener("input", refresh);

function refresh() {
    output.textContent = input.value.replace(/\S/g, m =>
        tran[m]??m
    );
}

refresh();
<textarea>hello world</textarea>
<div></div>
trincot
  • 317,000
  • 35
  • 244
  • 286