Re: Updating string/array items



In comp.lang.javascript message <Xns99CBDB791482Aeejj99@xxxxxxxxxxxxxxx>
, Tue, 16 Oct 2007 19:34:28, Evertjan. <exjxw.hannivoort@xxxxxxxxxxxx>
posted:

It is impossible to provide for all minor languages.

That'll upset the French.

O'Brian French?????

Well, he (Patrick) did live there.

<FAQENTRY>AISB, the FAQ is weak on RegExps. This topic would supply a
suitable example, perhaps presenting the simplest and the finest
solutions. I like the approach of your

String.prototype.toProper = function(){
return this.replace( /(\b\w)(\w*)/g ,
function(x,a,b){return a.toUpperCase()+b.toLowerCase();});
};

with a rearrangement of whitespace and a note about languages with
alphabets other than 26 A-Z.


For the OP : the simplest way may be to step character-by-character with
..charAt through the original string, noting whether the present
character is a letter and retaining one value of that in the next step,
and doing .toLowerCase or .toUpperCase accordingly before adding to what
has been processed so far.


But note that the test "Ban Ki-moon from RoK is S-G of the UN" could be
hard to pass by any method.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.



Relevant Pages

  • Re: [RFC][patch 02/12] remove clocksource inline functions
    ... So you only need to review one line in the ... simplest case. ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: Demonstration experiment
    ... The simplest is ... probably Coin the presence of concentrated chloride (I think it's in ... the sci.chem FAQ). ...
    (sci.chem)
  • [PATCH 04/13] drivers: gpu: drm: i915: Fix a typo.
    ... /* We need to copy these to an anonymous buffer as the simplest ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: Formatting data being displayed
    ... Where is your draft proposal for an entry on RegExps? ... current FAQ maintainer that posting such a draft will lead to a FAQ ... How can a RegExp trim whitespace - LTRIM/RTRIM/TRIM? ...
    (comp.lang.javascript)
  • Re: Syntax Question
    ... RegExps, and its links should show that the Boolean is true is S ... That FAQ section is out of date. ... But just cutting out the part which would fail is folly; ...
    (comp.lang.javascript)