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.
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
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));
}
}
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