0
In javascript
I can detect a character in a string and then write a letter before that character?
15 Answers
+ 2
// did you know regular expressions?
string = 'Heo world';
string = string.replace(/(?<=e)(?=o)/,'ll');
console.log(string);
+ 1
Ipang i have a text for example "heo word" i want to write "ll" between the letter "e" and "o"
for later eval with javascript
eval()
+ 1
visph thanks
0
What character to detect?
And where you write the letter?
Might help clear things up if you can provide an example.
0
share your code to get more accurate answer ;)
0
It for a calculator
https://code.sololearn.com/W5DWR1dC8808/?ref=app
0
You mean you read a string, for example
"Math. 9 x 2 ÷ 2"
Then you want the string to become
"9 * 2 / 2"
In order to be processed by eval()
0
For example
Text: cosh(5) -> Math.cosh(5)
Eval()
0
why don't you stuck at 'Math.'+string?
0
visph
?
eval("Math."+string)
?
0
just as you already do ^^
0
visph
could you explain me better
Sorry I'll be back in 2 hours I'm busy
0
You can make a list of function names e.g. [ "cos", "sin", "pow" ]. Then do a find & replace operation on the string before passing the string to eval().
let names = [ "sin", "cos", "tan" ];
for( let name of names )
{
// if string contains <name>
// replace it with "Math." + <name>
}