Skip to content

Strings

Mike edited this page May 28, 2014 · 1 revision

String Basics

module.exports.formLetter = function(firstName, senderName, message) {
  return "Hello " + firstName + ",\n\n" + message + "\n\nSincerely,\n" + senderName;
};

module.exports.sliceItAndCombineIt = function(bigString, startA, endA, startB, endB) {
  return bigString.substring(startA, endA) + bigString.substring(startB, endB);
};

module.exports.findFirstMatch = function(text, searchString) {
  return text.indexOf(searchString);
};

module.exports.findLastMatch = function(text, searchString) {
  return text.lastIndexOf(searchString);
};

module.exports.substringBetweenMatches = function(text, searchString) {
  firstMatchPosition = text.indexOf(searchString) + searchString.length;
  lastMatchPosition = text.lastIndexOf(searchString);
  return text.substring(firstMatchPosition, lastMatchPosition);
};
Clone this wiki locally