0

I hope you are well. So, as you can see, from "a-z" I have made a code to transcript every common letter (from "a" to "z") in some symbols. How can I do it when I want to transcript the letters "th" together in different symbol? I do not want the app to translate the letters "t" and "h" separately BUT together! How can I do that? Thank you so much!!!

var theInput = txtBr.value.toLowerCase();

for (var i = 0; i < theInput.length; i++)

 {
   
  
  var letter = theInput.charAt( i );
    
  if( letter.match(/[a-z\s]/i) ) {
    
    
    var symbol = map[ letter ];
    
    
    txtarea.innerHTML += symbol;
    
  }
  • Please add the code you've attempted to your question as a [mcve]. This means adding `map` dictionary, and some examples of expected output. – Andy Oct 24 '21 at 08:18
  • Dear, Welcome to Stack overflow. Please don't use sentences that are in form of a meeting dialogue( like "I hope you are well. So, as you can see, from "a-z"). these kind of extra and unnecessary things will make your questions or answers edited by the community. Good luck. – Aramis NSR Oct 27 '21 at 04:17

1 Answers1

1

string.search() will return the position of the substring you are searching for.

let string = "nspoiuthpiifs"; 
let position = string.search("th"); // will return 6

You could then split the string at that position with string.split(), replace the the "th" with the symbol you desire, then rejoin the string with array.join()

Note: string.search() will return only the position of the first one it finds, so you may want to repeat this method until there are none left.

Toby Scott
  • 79
  • 7