Menu

[r4]: / trunk / mere / str.js  Maximize  Restore  History

Download this file

25 lines (20 with data), 657 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (!this.mere) {var mere = {}}
mere.str = {
trim: function(str) {
return str.replace(/^\s*|\s*$/g,"")
},
capitalize: function(str) {
if (str.length == 0) return new String(str)
return str.substring(0,1).toUpperCase() + str.substring(1)
},
endsWith: function(str, suffix) {
if (suffix == null) throw new Error('Illegal argument: ' + suffix)
var position = str.length - suffix.length
if (position < 0) return false
return str.lastIndexOf(suffix, position) == position;
},
startsWith: function(str, prefix) {
if (prefix == null) throw new Error('Illegal argument: ' + prefix)
return str.substring(0, prefix.length) == prefix
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.