Answer to Question #173210 in HTML/JavaScript Web Application for hemanth

Question #173210

String Slicing

Given two strings

inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.
Input

  • The first line of input contains a string inputString
  • The second line of input contains a string subString

Output

  • The output should be a sliced string or inputString (if the inputString does not include the subString)


function main() {

 let inputString = readLine();

 const subString = readLine();

  

 /* Write your code here */

  

}


i want code in between write code here


1
Expert's answer
2021-03-19T11:14:19-0400
const inputString = 'JavaScript';
const subString = 'S';
console.log(inputString)
console.log('Sample Input 1');
console.log(subString.substr(inputString.substr(subString)));
// expected output: "Script"
console.log('Sample Output 1');
const subString2 = 'Script';
console.log(subString2.substr(inputString.substr(subString2)));
console.log('Sample Input 2');
const inputString2 = 'Language';
const subString3 = 'air';
console.log(inputString2);
console.log(subString3);
// expected output: "Language"
 if(inputString2.includes(subString3)) {
   console.log('Sample Output 2');
   console.log(subString3);
 }else{
   console.log('Sample Output 2');
   console.log(inputString2)
 }  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS