Created
September 4, 2015 19:35
-
-
Save zoghal/4917ac4b11e0ef2fe936 to your computer and use it in GitHub Desktop.
JavaStrings methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function StringUtil() { | |
this.reverseWords = function(str) { | |
var result = ""; | |
var wordArray = str.split(" "); | |
for(var i = wordArray.length - 1; i >= 0; i--) { | |
result += wordArray[i] + " "; | |
} | |
return result.trim(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.splitStr = function(delimiter) { | |
var stringArray = []; | |
var tempStr = ""; | |
for(var i = 0; i < this.length; i++) { | |
if(this.charAt(i) === delimiter) { | |
stringArray.push(tempStr); | |
tempStr = ""; | |
} else { | |
tempStr += this.charAt(i); | |
} | |
} | |
if(tempStr !== "") { | |
stringArray.push(tempStr); | |
} | |
return stringArray; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment