Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24909 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2014-06-18 12:39 -0700 |
| Last post | 2014-06-18 16:12 -0700 |
| Articles | 20 on this page of 24 — 4 participants |
Back to article view | Back to comp.lang.javascript
Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 12:39 -0700
Re: Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 13:09 -0700
Re: Can you change value of a substring? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-18 23:18 +0200
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-19 00:35 +0200
Re: Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 15:52 -0700
Re: Can you change value of a substring? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-18 16:14 -0700
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-18 22:10 +0200
Re: Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 13:17 -0700
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-18 22:52 +0200
Re: Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 14:03 -0700
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-19 00:07 +0200
Re: Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 15:28 -0700
Re: Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 13:20 -0700
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-18 23:22 +0200
Re: Can you change value of a substring? jonas.thornvall@gmail.com - 2014-06-18 14:40 -0700
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-19 00:31 +0200
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-18 23:42 +0200
Re: Can you change value of a substring? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-19 00:13 +0200
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-19 00:45 +0200
Re: Can you change value of a substring? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-19 01:32 +0200
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-19 09:43 +0200
Re: Can you change value of a substring? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-19 01:48 +0200
Re: Can you change value of a substring? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-06-19 09:56 +0200
Re: Can you change value of a substring? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-18 16:12 -0700
Page 1 of 2 [1] 2 Next page →
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 12:39 -0700 |
| Subject | Can you change value of a substring? |
| Message-ID | <a6d074ff-773b-42d0-96dc-31bd5d733e3d@googlegroups.com> |
Can i change value of a substring or do i have to read the string into an Array?
I want to change the value of substring a char in nstring. Is following possible?
nstring="12345"
n = nstring.length;
val=nstring.substring(n-1,n);
//Is it possible to subtract and add to the character in val?
val--;
//Can you force a value in a string or must i read into an array
nstring.substring(n-1,n)=val;
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 13:09 -0700 |
| Message-ID | <1f318ee5-a235-4ad0-93de-acde5d5ca317@googlegroups.com> |
| In reply to | #24909 |
Den onsdagen den 18:e juni 2014 kl. 21:39:21 UTC+2 skrev jonas.t...@gmail.com: > Can i change value of a substring or do i have to read the string into an Array? > > I want to change the value of substring a char in nstring. Is following possible? > > > > nstring="12345" > > n = nstring.length; > > > > val=nstring.substring(n-1,n); > > > > //Is it possible to subtract and add to the character in val? > > val--; > > > > //Can you force a value in a string or must i read into an array > > nstring.substring(n-1,n)=val; I've been Reading a Little more now from what i can see it will not be possible, so the most elegant solution is an Array from start? A simple yes or no will do.
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-06-18 23:18 +0200 |
| Message-ID | <53a20209$0$6671$9b4e6d93@newsspool3.arcor-online.net> |
| In reply to | #24911 |
jonas.thornvall@gmail.com wrote: > Den onsdagen den 18:e juni 2014 kl. 21:39:21 UTC+2 skrev > jonas.t...@gmail.com: > >> Can i change value of a substring or do i have to read the string >> into an Array? > > I've been Reading a Little more now from what i can see it will not > be possible, so the most elegant solution is an Array from start? > > A simple yes or no will do. Yes and no. That actually depends on the definition of "elegant" and what you really want to do. As has been already pointed out in this thread, ECMAScript strings are immutable. One way to get around this "limitation" (IMO it is none) is to transform the string to an array (using String.prototype.split), and to transform the array back to a string later (using Array.prototype.join). Another solution is to create a new string by concatenating pieces of the original string and some modifications. This may be more efficient, and is more flexible as it allows to "change" the length of the string. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-19 00:35 +0200 |
| Message-ID | <XnsA3516183B4ABeejj99@194.109.133.133> |
| In reply to | #24918 |
Christoph Michael Becker <cmbecker69@arcor.de> wrote on 18 jun 2014 in
comp.lang.javascript:
> jonas.thornvall@gmail.com wrote:
>
>> Den onsdagen den 18:e juni 2014 kl. 21:39:21 UTC+2 skrev
>> jonas.t...@gmail.com:
>>
>>> Can i change value of a substring or do i have to read the string
>>> into an Array?
>>
>> I've been Reading a Little more now from what i can see it will not
>> be possible, so the most elegant solution is an Array from start?
>>
>> A simple yes or no will do.
>
> Yes and no. That actually depends on the definition of "elegant" and
> what you really want to do.
>
> As has been already pointed out in this thread, ECMAScript strings are
> immutable. One way to get around this "limitation" (IMO it is none) is
> to transform the string to an array (using String.prototype.split), and
> to transform the array back to a string later (using
Array.prototype.join).
>
> Another solution is to create a new string by concatenating pieces of
> the original string and some modifications. This may be more efficient,
> and is more flexible as it allows to "change" the length of the string.
As I showed, the Regex replace() gives rather nice results:
<script type='text/javascript'>
var myString = '12345';
myString = myString.replace(/\d$/,incr);
alert(myString); // 12346
myString = myString.replace(/\d$/,incr);
alert(myString); // 12347
function incr(a){return +a+1};
// the first + is necessary for type conversion
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 15:52 -0700 |
| Message-ID | <89a076de-a693-4aac-b79a-4a9b30c2c27f@googlegroups.com> |
| In reply to | #24926 |
Den torsdagen den 19:e juni 2014 kl. 00:35:56 UTC+2 skrev Evertjan.:
> Christoph Michael Becker <cmbecker69@arcor.de> wrote on 18 jun 2014 in
>
> comp.lang.javascript:
>
>
>
> > jonas.thornvall@gmail.com wrote:
>
> >
>
> >> Den onsdagen den 18:e juni 2014 kl. 21:39:21 UTC+2 skrev
>
> >> jonas.t...@gmail.com:
>
> >>
>
> >>> Can i change value of a substring or do i have to read the string
>
> >>> into an Array?
>
> >>
>
> >> I've been Reading a Little more now from what i can see it will not
>
> >> be possible, so the most elegant solution is an Array from start?
>
> >>
>
> >> A simple yes or no will do.
>
> >
>
> > Yes and no. That actually depends on the definition of "elegant" and
>
> > what you really want to do.
>
> >
>
> > As has been already pointed out in this thread, ECMAScript strings are
>
> > immutable. One way to get around this "limitation" (IMO it is none) is
>
> > to transform the string to an array (using String.prototype.split), and
>
> > to transform the array back to a string later (using
>
> Array.prototype.join).
>
> >
>
> > Another solution is to create a new string by concatenating pieces of
>
> > the original string and some modifications. This may be more efficient,
>
> > and is more flexible as it allows to "change" the length of the string.
>
>
>
> As I showed, the Regex replace() gives rather nice results:
>
>
>
> <script type='text/javascript'>
>
>
>
> var myString = '12345';
>
>
>
> myString = myString.replace(/\d$/,incr);
>
> alert(myString); // 12346
>
>
>
> myString = myString.replace(/\d$/,incr);
>
> alert(myString); // 12347
>
>
>
> function incr(a){return +a+1};
>
> // the first + is necessary for type conversion
>
>
>
> </script>
>
>
>
>
>
>
>
>
>
> --
>
> Evertjan.
>
> The Netherlands.
>
> (Please change the x'es to dots in my emailaddress)
It seem useful Evertjan
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2014-06-18 16:14 -0700 |
| Message-ID | <95cdc303-f314-4467-8d99-d7094344e6fb@googlegroups.com> |
| In reply to | #24911 |
On Wednesday, June 18, 2014 3:09:54 PM UTC-5, jonas.t...@gmail.com wrote: > > I've been Reading a Little more now from what i can see it will not be possible, so the most elegant solution is an Array from start? > > A simple yes or no will do. If you plan on manipulating individual "digits" frequently, then yes, probably a wiser approach
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-18 22:10 +0200 |
| Message-ID | <XnsA350E19EA17B4eejj99@194.109.133.133> |
| In reply to | #24909 |
jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript: > Can i change value of a substring or do i have to read the string into > an Array? I want to change the value of substring a char in nstring. Is > following possible? > > nstring="12345" > n = nstring.length; > > val=nstring.substring(n-1,n); > > //Is it possible to subtract and add to the character in val? > val--; What where the results from your testing it? Ever heard of automatic type conversion? > //Can you force a value in a string or must i read into an array > nstring.substring(n-1,n)=val; There is no "value in a string". Jvascript is no old style basic. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 13:17 -0700 |
| Message-ID | <8cd1560f-c83b-49e0-af42-70a7568f95c1@googlegroups.com> |
| In reply to | #24912 |
Den onsdagen den 18:e juni 2014 kl. 22:10:45 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript:
>
>
>
> > Can i change value of a substring or do i have to read the string into
>
> > an Array? I want to change the value of substring a char in nstring. Is
>
> > following possible?
>
> >
>
> > nstring="12345"
>
> > n = nstring.length;
>
> >
>
> > val=nstring.substring(n-1,n);
>
> >
>
> > //Is it possible to subtract and add to the character in val?
>
> > val--;
>
>
>
> What where the results from your testing it?
>
>
>
> Ever heard of automatic type conversion?
>
>
>
> > //Can you force a value in a string or must i read into an array
>
> > nstring.substring(n-1,n)=val;
>
>
>
> There is no "value in a string".
>
>
>
> Jvascript is no old style basic.
>
>
>
>
>
>
>
>
>
> --
>
> Evertjan.
>
> The Netherlands.
>
> (Please change the x'es to dots in my emailaddress)
I've alrady decided to go for an Array and using
var n = 123456789;
var digits = (""+n).split("");
And use fruits.length; for your answer.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-18 22:52 +0200 |
| Message-ID | <XnsA350E8C0F7C03eejj99@194.109.133.133> |
| In reply to | #24913 |
jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript:
> Den onsdagen den 18:e juni 2014 kl. 22:10:45 UTC+2 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript:
>>
>>
>>
>> > Can i change value of a substring or do i have to read the string into
[...]
>
> I've alrady decided to go for an Array and using
That is fine, but does not validate
the wrong premisses in your Q.
> var n = 123456789;
> var digits = (""+n).split("");
>
> And use fruits.length; for your answer.
my answer ?????????????????
Oh come!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 14:03 -0700 |
| Message-ID | <37ec2c2c-b5be-4c81-a2ef-11d234d4eb3b@googlegroups.com> |
| In reply to | #24916 |
Den onsdagen den 18:e juni 2014 kl. 22:52:50 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript:
>
>
>
> > Den onsdagen den 18:e juni 2014 kl. 22:10:45 UTC+2 skrev Evertjan.:
>
> >> jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript:
>
> >>
>
> >>
>
> >>
>
> >> > Can i change value of a substring or do i have to read the string into
>
> [...]
>
> >
>
> > I've alrady decided to go for an Array and using
>
>
>
> That is fine, but does not validate
>
> the wrong premisses in your Q.
>
>
>
> > var n = 123456789;
>
> > var digits = (""+n).split("");
>
> >
>
> > And use fruits.length; for your answer.
>
>
>
> my answer ?????????????????
>
>
>
> Oh come!
>
>
>
> --
>
> Evertjan.
>
> The Netherlands.
>
> (Please change the x'es to dots in my emailaddr
No offense meant just tried to be funny, but i find it strange there is people of a certain mentality who never try to answer the actual question. Instead they try to take people for a ride in the funny park.
It is not even an attempt of answer, and sure there is alot of values in a string, they are represented by ascii character on the screen, and i am not really that interested how they are stored internally.
I just wanted to know if you could replace a subset of a string with another string, and it simply not possible.
But what your answer hint on just eludes me.
There is no "value in a string".
Jvascript is no old style basic.
Honestly it is just weird.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-19 00:07 +0200 |
| Message-ID | <XnsA351148F300Feejj99@194.109.133.133> |
| In reply to | #24917 |
jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript: > No offense meant just tried to be funny, but i find it strange there is > people of a certain mentality who never try to answer the actual > question. Usenet is not a helpdesk or anwswering service. Why do you presume we should try? You might learn something by not prescribing the way your postings should be responded on. > Instead they try to take people for a ride in the funny park. That might be your interpertation, Jonas, but then it is just that. > It is not even an attempt of answer, and sure there is alot of values in > a string, they are represented by ascii character on the screen, You might be sure, but it is untrue IMHO. When printed on the screen or on paper by a write method, like write(), innerHTML, or DOM methods, unicode and NOT ASCII [!!!] is presumed. But that does not make a string "containing" that. > and i am not really that interested how they are stored internally. Sorry, I think it is not very important where you are interested in, as, again, this is usenet, and not a paid helpdesk. Prescribing what responses you want is not the way of usenet. My postings are not aimed to please you or to take you on a ride, though the result might be felt either way. Postings are not even ment for you, but for the group, as usenet is not email. > I just > wanted to know if you could replace a subset of a string with another > string, and it simply not possible. But what your answer hint on just > eludes me. While it is not possible, it is not SIMPLY so, as there are reasons for this not possible. Perhaps you are not interested in why it is not possible. This is a pity, as you will keep misunderstanding Javascript methods, and such understanding is IMHO the basis of efficient programming. >>> Re: Can you change value of a substring? Your postulate that substr() "contains" a string, while it just "returns" a string, was the start of your, now it shows willfully, misunderstanding of the subject. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 15:28 -0700 |
| Message-ID | <865c2a35-d0fb-4be8-a90f-a393b0ae4d26@googlegroups.com> |
| In reply to | #24922 |
Den torsdagen den 19:e juni 2014 kl. 00:07:34 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript: > > > > > No offense meant just tried to be funny, but i find it strange there is > > > people of a certain mentality who never try to answer the actual > > > question. > > > > Usenet is not a helpdesk or anwswering service. > > Why do you presume we should try? > > You might learn something by not prescribing the way your postings should be > > responded on. > > > > > Instead they try to take people for a ride in the funny park. > > > > That might be your interpertation, Jonas, but then it is just that. > > > > > It is not even an attempt of answer, and sure there is alot of values in > > > a string, they are represented by ascii character on the screen, > > > > You might be sure, but it is untrue IMHO. > > > > When printed on the screen or on paper by a write method, like write(), > > innerHTML, or DOM methods, unicode and NOT ASCII [!!!] is presumed. > > > > But that does not make a string "containing" that. > > > > > and i am not really that interested how they are stored internally. > > > > Sorry, I think it is not very important where you are interested in, > > as, again, this is usenet, and not a paid helpdesk. > > > > Prescribing what responses you want is not the way of usenet. > > > > My postings are not aimed to please you or to take you on a ride, though the > > result might be felt either way. Postings are not even ment for you, but for > > the group, as usenet is not email. > > > > > I just > > > wanted to know if you could replace a subset of a string with another > > > string, and it simply not possible. But what your answer hint on just > > > eludes me. > > > > While it is not possible, it is not SIMPLY so, as there are reasons for this > > not possible. Perhaps you are not interested in why it is not possible. > > This is a pity, as you will keep misunderstanding Javascript methods, > > and such understanding is IMHO the basis of efficient programming. > > > > >>> Re: Can you change value of a substring? > > > > Your postulate that substr() "contains" a string, while it just "returns" a > > string, was the start of your, now it shows willfully, misunderstanding of > > the subject. > > > > -- > > Evertjan. > > The Netherlands. > > (Please change the x'es to dots in my emailaddress) I consider myself a puzzle solver more then a "Ecmascript programmer", thus for me it is uninteresting if the problem is solved with farts and feathers or using gold and platina. That said programming languages is just tools for solving problems, and you are probably right in that a craftsman should learn its tools. Well that make me a bad craftsman, but a decent problem solver. And one think of the depth and width of the problems computer programming might be able to solve, i probably rather be a decent problem solver then a fullblown craftsman. But in the end you are correct there is no restriction to be both. But most problem related to craftmanship can ba solved within 3-10 searches today. And that is maybe why i find the craftmanship of programming a bit boring the hammer in itsef not that exciting to me. However sometimes questions can spawn new ideas, and i suspected from start what i asked was not possible. But then i asked why, and decided to post because maybe it raise questions about Javascript and programming languages in general?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 13:20 -0700 |
| Message-ID | <cfc0ab9a-3ab2-4029-89ef-24282d7fc696@googlegroups.com> |
| In reply to | #24912 |
Den onsdagen den 18:e juni 2014 kl. 22:10:45 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript: > > > > > Can i change value of a substring or do i have to read the string into > > > an Array? I want to change the value of substring a char in nstring. Is > > > following possible? > > > > > > nstring="12345" > > > n = nstring.length; > > > > > > val=nstring.substring(n-1,n); > > > > > > //Is it possible to subtract and add to the character in val? > > > val--; > > > > What where the results from your testing it? > > > > Ever heard of automatic type conversion? > > > > > //Can you force a value in a string or must i read into an array > > > nstring.substring(n-1,n)=val; > > > > There is no "value in a string". > > > > Jvascript is no old style basic. > > > > > > > > > > -- > > Evertjan. > > The Netherlands. > > (Please change the x'es to dots in my emailaddress) Well the substring do contain an ascii set of values and i simply was asking if that subset was replacabel with Another set of ascii values is that such a weird question?
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-18 23:22 +0200 |
| Message-ID | <XnsA350EDC4CEDE5eejj99@194.109.133.133> |
| In reply to | #24914 |
jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript: > Well the substring do contain an ascii set of values and i simply was > asking if that subset was replacabel with Another set of ascii values is > that such a weird question? Yes, it is weird, because the functions substr() and substring() do NOT CONTAIN anything, but return something: a string. Yes, it is weird, because a string is not "an ascii set of values", in the sense that you can manipulate the string in its memory location. [Well it is not weird, because there are no silly questions, weird is just the word you introduced] It isn't even the ASCII set but the much larger Unicode set. This Unicode only is defined with reading and writing, internally it is just a series of [16bit, I think] slots you might define in any way you like. In Javascript you can only manipulate a string and place the returned result in a NEW memory location pointed at by a named variable pointer. This named variable pointer might be the same as the one you got the string to be manipulated from, but the memory location is not the same one: var myString = "blahblah"; [makes an internal pointer for myString to a memory location where this string is just stored] myString = myString + "123" + myString; [replaces the internal pointer for myString with one that points to a new memory location of the totally new (and here longer) string.] When the old memory is no longer pointed at, the "garbage collector" will take care of that sooner [or later] and makes that memory available again. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-06-18 14:40 -0700 |
| Message-ID | <3c78f76c-fc9f-4475-bbe0-b5e25893fcda@googlegroups.com> |
| In reply to | #24919 |
Den onsdagen den 18:e juni 2014 kl. 23:22:24 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript: > > > > > Well the substring do contain an ascii set of values and i simply was > > > asking if that subset was replacabel with Another set of ascii values is > > > that such a weird question? > > > > Yes, it is weird, because the functions substr() and substring() > > do NOT CONTAIN anything, but return something: a string. > > Honestly Jan i do not give a shit of the meticolusly inner works of the functions substr() and substring(). But from a meta parspective and a bit naive maybe i was thinking that it could be possible to feed the function calls with parameters to change the substring, thus when assigning a value (char, int) using automatic type conversion. You could also use the function not just to read out substrings but also to change/update them. And people in this thread told me " It just so happens that a string also is immutable," which i interpretate they can not be changed." Here is your answer "There is no "value in a string". Jvascript is no old style basic." A bit unprecise maybe or are you aiming at the wrong goal? > Yes, it is weird, because a string is not "an ascii set of values", > > in the sense that you can manipulate the string in its memory location. > > > > [Well it is not weird, because there are no silly questions, weird is just > > the word you introduced] > > > > It isn't even the ASCII set but the much larger Unicode set. > > This Unicode only is defined with reading and writing, internally it is just > > a series of [16bit, I think] slots you might define in any way you like. > > > > In Javascript you can only manipulate a string and place the returned result > > in a NEW memory location pointed at by a named variable pointer. > > > > This named variable pointer might be the same as the one you got the string > > to be manipulated from, but the memory location is not the same one: > > > > var myString = "blahblah"; > > [makes an internal pointer for myString to a memory location where this > > string is just stored] > > > > myString = myString + "123" + myString; > > [replaces the internal pointer for myString with one that points to a new > > memory location of the totally new (and here longer) string.] > > > > When the old memory is no longer pointed at, the "garbage collector" > > will take care of that sooner [or later] and makes that memory available > > again. > > > > > > -- > > Evertjan. > > The Netherlands. > > (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-19 00:31 +0200 |
| Message-ID | <XnsA3515515EA31eejj99@194.109.133.133> |
| In reply to | #24920 |
jonas.thornvall@gmail.com wrote on 18 jun 2014 in comp.lang.javascript:
> Honestly Jan
Jonas, my name is not Jan.
> i do not give a shit of
I am not interested in your bowel movements.
> the meticolusly inner works of the functions substr() and substring().
Well you should, Javascript has strings as variable values, but NOT
substrings.
Your false premisse lead to your misunderstanding.
> But from a meta parspective and a
Please [for your sake] do not have perspectives meta or not,
that have no logic in the functionning of Javascript.
> bit naive maybe i was thinking that it could be possible to feed the
> function calls
What function calls?
> with parameters to change the substring,
Javascript has no substrings, just the methods substr() and substring(),
which both just return a string.
If you mean these methods, even if that was possible, it would only affect
the resulting returned string.
You might look into the marvelously implemented Regular Expression methods,
like replace(). replace() makes it possible to have a fully manipulated
string returned wich you can assign to the old string's variable.
TRY THIS:
<script type='text/javascript'>
var myString = '12345';
myString = myString.replace(/\d$/,incr);
alert(myString); // 12346
myString = myString.replace(/\d$/,incr);
alert(myString); // 12347
function incr(a){return 1+ +a};
</script>
Being naive is fine, but protesting against the incidental revealing is not.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-18 23:42 +0200 |
| Message-ID | <XnsA350F12DEEDEBeejj99@194.109.133.133> |
| In reply to | #24912 |
ram@zedat.fu-berlin.de (Stefan Ram) wrote on 18 jun 2014 in comp.lang.javascript: > "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes: >>There is no "value in a string". > > A string is a finite sequence of values, which are characters. No. A Javascript string is an enormous large number of bits, interpreted by most methods as 16 bit values, which can be interpreted as characters, but that does not have to be so. Only the standard read and write methods implement them as Unicode. > It just so happens that a string A Javascript string, not any string. > also is immutable, so you > cannot change those values »in place«. I would say: in its memory location. > (This shows that JavaScript has something to do with Java, > because about strings in Java one can say the same.) An analog clock and a human usually have hands, does that fact mean they have "something to do" with eachother? Perhaps you can say the same near truth in both languages. The same would apply to Javascript and VBS. And perhaps many other languages. But that is realy the implementation, you could easily device a Javascript engine that manipulates smaller strings "in place" by either ensuring the result is not larger than the original or reserving a fixed amount of memory for such strings. This would increase string manipulation of smaller strings cpu efficiency tremendously while using the present way for larger ones. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-06-19 00:13 +0200 |
| Message-ID | <53a20f16$0$6670$9b4e6d93@newsspool3.arcor-online.net> |
| In reply to | #24921 |
Evertjan. wrote: > ram@zedat.fu-berlin.de (Stefan Ram) wrote on 18 jun 2014 in > comp.lang.javascript: > >> (This shows that JavaScript has something to do with Java, >> because about strings in Java one can say the same.) > > An analog clock and a human usually have hands, > does that fact mean they have "something to do" with eachother? Thumbs up! :) > But that is realy the implementation, you could easily device a Javascript > engine that manipulates smaller strings "in place" by either ensuring the > result is not larger than the original or reserving a fixed amount of memory > for such strings. This would increase string manipulation of smaller strings > cpu efficiency tremendously while using the present way for larger ones. I beg to differ that this is only related to the implementation, even if I ignore the ECMAScript specification. Mutable strings vs. immutable strings are an important *semantic* concept for the programmer. Consider passing a string as argument to a function; if the function is able to actually change the string, the programmer has to be aware of that and cater for it (especially when writing a library). (Of course, internally strings could be manipulated in place, while still maintaining seemingly immutability of strings with a copy-on-write[1] implementation. And of course, there are ropes[2] to avoid excessive copying.) [1] <http://en.wikipedia.org/wiki/Copy-on-write> [1] <http://en.wikipedia.org/wiki/Rope_(data_structure)> -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-06-19 00:45 +0200 |
| Message-ID | <XnsA3517C4494D0eejj99@194.109.133.133> |
| In reply to | #24924 |
Christoph Michael Becker <cmbecker69@arcor.de> wrote on 19 jun 2014 in
comp.lang.javascript:
> I beg to differ that this is only related to the implementation,
I did not say that,
I said it is possible to write a Javascript engine that can.
Would that be forbidden by the ECMA specs?
> Mutable strings vs. immutable strings are
> an important *semantic* concept for the programmer.
I don't think so.
All variables in Javascript are in a sense immutable,
but some shorthand operators make it seem they are.
You might say [ I say only apparently so ]
i++;
shows mutability.
But [seen the inner workings of string concatenation]
mystring += " add this to the string";
certainly not.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-06-19 01:32 +0200 |
| Message-ID | <53a22171$0$6664$9b4e6d93@newsspool3.arcor-online.net> |
| In reply to | #24927 |
Evertjan. wrote:
> Christoph Michael Becker <cmbecker69@arcor.de> wrote on 19 jun 2014 in
> comp.lang.javascript:
>
>> I beg to differ that this is only related to the implementation,
>
> I did not say that,
> I said it is possible to write a Javascript engine that can.
> Would that be forbidden by the ECMA specs?
I am surprised, but it seems that the ECMAScript specification, edition
5.1, does not explicitely specify that strings are immutable (please
CMIIW). However, AFAIK none of the specified string methods actually
change the string in place.
>> Mutable strings vs. immutable strings are
>> an important *semantic* concept for the programmer.
>
> I don't think so.
>
> All variables in Javascript are in a sense immutable,
> but some shorthand operators make it seem they are.
I'm talking about *values*, not *references* to values (e.g. variables
referencing these values).
> You might say [ I say only apparently so ]
> i++;
> shows mutability.
>
> But [seen the inner workings of string concatenation]
> mystring += " add this to the string";
> certainly not.
To understand my point, consider the following three programs:
var n = 42;
doIt(n);
alert(n == 42);
and:
var s = "something";
doIt(s);
alert(s == "something");
and:
var a = [1, 2, 3];
doIt(a);
alert(a == [1, 2, 3]);
While the first two programs always will display "true" (independent of
the definition of doIt), the third may not, for instance for the
following definition of doIt:
function doIt(array) {
array.splice(1, 1);
}
Thus I'd say numbers and strings are immutable, but arrays are not.
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web