In comp.lang.javascript message <047e4ef5-2b45-4460-b6a7-c289702f5060@d2
1g2000prf.googlegroups.com>, Wed, 26 Dec 2007 05:57:52, groovyd
<go****@groovydomain.composted:
>hi everyone, i have programmed quite extensively in C and C++ but am a
newbie to javascript and am currently busy working my way through
'javascript: The Definitive Guide', a great book infact.
You may find the pocket version also useful if the full one is just too
physically big at times, though I suspect there is no recent edition.
>A question i have is in the inability for java to mutate (change)
Strings, like string[3]='a'; kindof thing. Could someone please tell
me why?
Java is not Javascript.
Maybe so that there can be multiple references to a string without
needing to worry about dealing for the need to change what one reference
sees.
Seems like an important ability to be able to edit your
strings directly without forming another. atleast in C it was.
It's never *necessary* to do exactly that, and one can write a
subroutine to implant a character in a given position in a copy of a
string. However, when frequently handling strings which are large or
numerous, do seek efficient plans with minimum bulk copying. It appears
that the implementation of array.join() is efficient.
>and speaking of hard to learn tricks... i am new to regex and am
trying to figure out an equivalent expression which would allow me to
replace a character of a string at a certain character position such
as string[3]='a'. i am assuming you do this sort of thing through the
regex replace() function?
/\w^\S*{3,5}(\n)+/... errrrrrrrrrrrr....
Not necessarily. For S2 := S1 ; S2[3] := 'a' ;
you can do, for example
S2 = S1.substring(0, 2) + 'a' + S1.substring(3)
in which the indexes may need adjusting.
To do a lot, .split("") the string into an array, assign elements, and
..join("") .
I suspect that constructing and using a RegExp would not usually be
significantly faster - you can test that by taking a copy of <URL:http:/
/www.merlyn.demon.co.uk/js-quick.htmand pressing Demo six times
without undue haste then inserting code. ... Using .substring seems
about twice as fast as using new RegExp.
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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.