String Manipulations through Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vivek kapile
    New Member
    • Mar 2011
    • 17

    String Manipulations through Javascript

    Title: String Manipulations through Javascript
    Author: Vivek Kapile
    Email: snipped
    Language: JavaScript
    Platform: Javascript
    Technology: JavaScript
    Level: Beginner

    Introduction
    This code will help for the beginners, who want to learn, how to manage a substring through Javascript.
    for ex. @Right("Vivek", "i") returns "vek"


    Description:

    Below is a sample code.

    Code:
    function rightString(fullString, subString) {
       if (fullString.indexOf(subString) == -1) {
          return "";
       } else {
          return (fullString.substring(fullString.indexOf(subString)+subString.length, fullString.length));
       }
    }
    
    
    function rightBackString(fullString, subString) {
       if (fullString.lastIndexOf(subString) == -1) {
          return "";
       } else {
          return fullString.substring(fullString.lastIndexOf(subString)+1, fullString.length);
       }
    }
    
    
    function middleString(fullString, startString, endString) {
       if (fullString.indexOf(startString) == -1) {
          return "";
       } else {
          var sub = fullString.substring(fullString.indexOf(startString)+startString.length, fullString.length);
          if (sub.indexOf(endString) == -1) {
             return sub;
          } else {
             return (sub.substring(0, sub.indexOf(endString)));
          }
       }
    }
    
    
    function middleBackString(fullString, startString, endString) {
       if (fullString.lastIndexOf(startString) == -1) {
          return "";
       } else {
          var sub = fullString.substring(0, fullString.lastIndexOf(startString));
          if (sub.indexOf(endString) == -1) {
             return sub;
          } else {
             return (sub.substring(sub.indexOf(endString)+endString.length, sub.length));
          }
       }
    }
    
    
    function leftString(fullString, subString) {
       if (fullString.indexOf(subString) == -1) {
          return "";
       } else {
          return (fullString.substring(0, fullString.indexOf(subString)));
       }
    }
    
    
    function leftBackString(fullString, subString) {
       if (fullString.lastIndexOf(subString) == -1) {
          return "";
       } else {
          return fullString.substring(0, fullString.lastIndexOf(subString));
       }
    }
    Summary

    There are many topics to learn with Javascript. I have covered a small portion hope this will helps all the beginners to start up. Please give your feedback and suggestion.

    History

    * Written on 17-March-2011, Thursday


    References

    License

    This article, along with any associated source code and files, is licensed under The Bytes

    About the Author

    Vivek kapile
    Developer
    India,Bangalore
    Last edited by Frinavale; Jun 7 '11, 05:36 PM. Reason: Fixed spelling errors. Changed the title mentioned in the body to match the title of the thread. Changed the mentioned technologies-used to match the technology used in the thread.
Working...