JSFiddle - React, Tailwind, and code Playground

by soumya gangamwar

JavaScript

function rePlaceString (data, annotationName, userInput) {

      const startBtagIndex = data.indexOf('<b>');
      const endBtagIndex = data.indexOf('</b>');
      const startItagIndex = data.indexOf('<i>');
      const endItagindex = data.indexOf('</i>');
      
      if ((startBtagIndex > 0 && endBtagIndex > 0) && (startItagIndex > 0 && endItagindex >0)) {
       	let replaceString = '';
        replaceString = data.substring(0, startItagIndex) + userInput + data.substr(endItagindex, data.length);
        replaceString = replaceString.substring(0, startBtagIndex) + annotationName + replaceString.substr(endItagindex, currentStep.annotationName)
      } else if (startBtagIndex > 0 && endBtagIndex > 0) {
      
      } else if (startItagIndex > 0 && endItagindex >0) {
      
      }
      
      
      
   // expected Result 
    return {displayData: `And I should input <i> ${annotationName}</i> as <b>${userInput}</b>`, requestData: `And I should input  '${annotationName}' as '${userInput}'`};
    
}

console.log(rePlaceString(`And I should input <i>Annotaion</i> as <b>inoutUserName</b>`, 'UserName', 'Admin'), '***********')

console.log(rePlaceString(`And I should navigate to <b>Input</b>`, 'UserName', 'Admin'), '!!!!!!!!!!!!!!!!!!!!!!!')