Case insensitive String startsWith, contains, endsWith, replaceAll method
Rick Waldron
waldron.rick at gmail.com
Sat Feb 16 18:01:54 PST 2013
On Saturday, February 16, 2013, David Bruant wrote:
> Le 17/02/2013 00:58, Biju a écrit :
>
>> In most time when user want to search something in a text, he/she
>> wants to do a case insensitive search.
>> For example to filter items displayed in list on a page.
>> Also on other applications, say any word processor, or in page search
>> in Firefox, IE, Chrome etc.
>>
>> So can we make the default behavior of new methods String.startsWith,
>> String.contains, String.endsWith case insensitive?
>>
> I think all current methods are case-sensitive. If these methods were to
> be made case-insensitive, someone else would come on the list demanding
> consistency.
Here I am, demanding consistency. The default should match the behavior of
the language's comparison algorithms.
> Also, it doesn't seem that hard to implement:
> String.prototype.startsWithI = function(s){
> this.match(new RegExp('^'+s, 'i'));
> }
>
> And sometimes, case-sensitive is what you want.
Arguably most of the time. If I want case-insensitive, I will do the extra
work for it.
> And to make it case sensitive we should add a third flag parameter
>> matchCase
>> like...
>>
>> var startsWith = str.startsWith(searchString [, position [, matchCase] ]
>> );
>> var contained = str.contains(searchString [, position [, matchCase] ] );
>> var endsWith = str.endsWith(searchString [, position [, matchCase] ] );
>>
>>
>> Additionally we should have a String.replaceAll method right now web
>> developers are using complex logic to achieve the same.
>>
> "aA".replace(/a/ig, 'b'); // 'bb'
> I feel the "i" and "g" flag or regexps aren't that complex. One just needs
> to know about them.
+1
I'd go so far as saying that none of these are necessary additions in the
first place—conveniences at best.
Rick
>
> David
> ______________________________**_________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130216/b4a096d9/attachment.html>
More information about the es-discuss
mailing list