I have been working on a a web-based project for sometime now. Because of the diverse requirements on the system, I was required to have as many interactions with the users' data from a client-side point of view. I could not find inbuilt functions that could solve my problems. So I was compelled to extend the String object so as to suit my needs.
I should admit that they may not be all that robust to take pride in, but they are able to do what I wanted any way! I believe that there exists someone like me, looking for same (if not similar) functions and probably they are tired with googling. There might also be some who are working on some standardized library and may have been thinking of functions likes these. I guess this will be a starting point for both.
I have tried to make them very simple (simple in all senses) and straightforward, but if you have questions, keep them flowing. We are here to help each other. Constructive criticisms and suggestions are surely welcome!!
Programming hint: In each of these functions, You can improve the split functions to make comparisons using regular expression matching
NB: Forgive me for poor formatting. I didn't have enough time to create a custom css file!
I should admit that they may not be all that robust to take pride in, but they are able to do what I wanted any way! I believe that there exists someone like me, looking for same (if not similar) functions and probably they are tired with googling. There might also be some who are working on some standardized library and may have been thinking of functions likes these. I guess this will be a starting point for both.
I have tried to make them very simple (simple in all senses) and straightforward, but if you have questions, keep them flowing. We are here to help each other. Constructive criticisms and suggestions are surely welcome!!
Programming hint: In each of these functions, You can improve the split functions to make comparisons using regular expression matching
- contains() function /* checks for the presence of a substring in a given string of
- capitalize() function
- titleize() function
* semi-colon separated substrings.
* it returns 'true' if found, otherwise it returns 'false'
*
* for example :
* 1. ["programming;in;javascript;is;cool"].contains("javascript") => true
* 2. ["programming;in;javascript;is;cool"].contains("java") => false
*
* TO DO: ADD HANDLING OF 'SPACE' SEPARATED SUBSTRINGS
*
*/
String.prototype.contains = function (substring) {
var array_of_strings = this.split(';');
if (jQuery.inArray(substring, array_of_strings)>= 0) {
return true;
}
else {
return false;
}
}
/* capitalizes a given string
* Author: Edmond Kachale
* for example :
* "ProGraMming Is CooL".capitalize() => "Programming is cool"
*/
String.prototype.capitalize = function(){
var capitalized_string = new Array();
if((this.length> 0)){
capitalized_string.push(this[0].toUpperCase());
capitalized_string.push(this.substring(1,this.length).toLowerCase());
return capitalized_string.join("");
}
else{
return this;
}
}
This function depends on capitalize() function above
/* "titleizes" a given string
* Author: Edmond Kachale
* for example :
* "Programming is cool".titleize() => "Programming Is Cool"
*/
String.prototype.titleize = function(){
var titleized_string = new Array();
var sub_strings = this.split(" ");
for(i = 0; i <this.length; i++)
titleized_string.push(sub_strings[i].capitalize());
return titleized_string.join(" ");
}
* Author: Edmond Kachale
* for example :
* "ProGraMming Is CooL".capitalize() => "Programming is cool"
*/
String.prototype.capitalize = function(){
var capitalized_string = new Array();
if((this.length> 0)){
capitalized_string.push(this[0].toUpperCase());
capitalized_string.push(this.substring(1,this.length).toLowerCase());
return capitalized_string.join("");
}
else{
return this;
}
}
This function depends on capitalize() function above
/* "titleizes" a given string
* Author: Edmond Kachale
* for example :
* "Programming is cool".titleize() => "Programming Is Cool"
*/
String.prototype.titleize = function(){
var titleized_string = new Array();
var sub_strings = this.split(" ");
for(i = 0; i <this.length; i++)
titleized_string.push(sub_strings[i].capitalize());
return titleized_string.join(" ");
}
NB: Forgive me for poor formatting. I didn't have enough time to create a custom css file!
nyatwa
ReplyDeleteInteresting Article
ReplyDeleteJavascript Training in Chennai | Javascript Online Training | Javascript Online Training | Javascript Online Course
Wow. This really made my day. Thanks a lot!
ReplyDeleteHTML5 Training in Chennai | JavaScript Training in Chennai | Javascript Online Course India | Angularjs Training in Chennai
Angularjs Training in Chennai | Backbone.JS Training in Chennai | Bootstrap Training in Chennai |
ReplyDeleteNode.js Training in Chennai
Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
ReplyDeleteSelenium training in Chennai
Selenium training in Bangalore
ReplyDeleteThis is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
This comment has been removed by the author.
ReplyDeleteVery nice post here thanks to you for this. I evermore like your blog and such a useful content of these post. Keep doing...
ReplyDeleteCorporate Training in Chennai
Corporate Training institute in Chennai
Spark Training in Chennai
Social Media Marketing Courses in Chennai
Job Openings in Chennai
Oracle Training in Chennai
Tableau Training in Chennai
Power BI Training in Chennai
Linux Training in Chennai
Corporate Training in OMR
Really very nice blog information for this one and more technical skills are improving, I like that kind of post.
ReplyDeleteeTechno Soft Solutions is a leading training institute for all kind of the Oracle Training in Bangalore with real-time experienced trainers with 100% Placement Assistance.
its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeletepython training in chennai
python online training in chennai
python training in bangalore
python training in hyderabad
python online training
python flask training
python flask online training
python training in coimbatore
Great Blog. Thanks for sharing.
ReplyDeleteJava course in Pune