-3

I know this will be a simple question. I am new coding and still have a lot to learn. I am running a movie API with node. As you know API's searches cannot have spaces " " and need a plus sign "+" in order to search a string. Example when I search Die Hard on the terminal it comes back as a movie called Die and does not recognize "Hard". If I search it as Die+Hard I will get the movie I am looking for. How do I add that plus sign without having the user write the plus sign in the search? Thank you for your help.

var axios = require("axios");

movieName = (process.argv[2]);


var queryUrl = "http://www.omdbapi.com/?t=" + movieName + "&y=&plot=short&apikey=...";
hong4rc
  • 3,999
  • 4
  • 21
  • 40
logan k
  • 7
  • 3
  • 3
    Possible duplicate of [Fastest method to replace all instances of a character in a string](https://stackoverflow.com/questions/2116558/fastest-method-to-replace-all-instances-of-a-character-in-a-string) – CertainPerformance Feb 17 '19 at 00:47

2 Answers2

0

To replace all instances of a space in a string (let's call it str) with +:

str.replace(/ /g, "+");

To replace all instances of any whitespace characters with a +:

str.replace(/\s/g, "+");

For more information, see the MDN docs on String.prototype.replace().

Trott
  • 66,479
  • 23
  • 173
  • 212
0

var movieName = process.argv.slice(2).join("+");

this took care of it. Thank you for the help.

logan k
  • 7
  • 3