473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String Indexes

I was perusing the book Pure Javascript by Wyke, Gilliam, and Ting and came
upon references to String Indexes on pages 32-33 in the discussion of
arrays.

I then looked for more info in the 3rd edition of David Flanagan's
Javascript The Definitive Guide. I found no mention of String Indexes.
Is this book out of date?

Do I need to get a newer edition?
Which books?

--
http://www.standards.com/; See Howard Kaikow's web site.
Jul 23 '05 #1
5 1673
Howard Kaikow wrote:
I was perusing the book Pure Javascript by Wyke, Gilliam, and Ting and came
upon references to String Indexes on pages 32-33 in the discussion of
arrays.

I then looked for more info in the 3rd edition of David Flanagan's
Javascript The Definitive Guide. I found no mention of String Indexes.
Is this book out of date?

Do I need to get a newer edition?
Which books?


I'm guessing you are looking for indexOf and lastIndexOf.

A Google search for "javascript string index" turned up the
following useful reference:

http://www.quirksmode.org/js/strings.html

The FAQ provides some help with regular expressions in general:

http://www.jibbering.com/faq/

No doubt there are hundreds more resources online -
searching for regular expression links should further
complete the picture.

Rob.
Jul 23 '05 #2
> I'm guessing you are looking for indexOf and lastIndexOf.

Nope, string index for arrays is not stringmanipulation. For example:

var Stuff= new Array();
Stuff["Yankees"]=10;
Stuff["Red Sox"]=7;
Stuff["Bagels"]=13;
Stuff["Pizza"]=3;
document.write("<BR>Yankees= " + Stuff['Yankees']);
document.write("<BR>Red Sox= " + Stuff['Red Sox']);
document.write("<BR>Bagels= " + Stuff['Bagels']);
document.write("<BR>Pizza= " + Stuff['Pizza']);
Jul 23 '05 #3
"Howard Kaikow" <ka****@standards.com> wrote:
I then looked for more info in the 3rd edition of David Flanagan's
Javascript The Definitive Guide. I found no mention of String Indexes.
Is this book out of date?

Highly doubtful. I've never heard the term 'string indexes' before.
Look for information on objects and properties. In MS JScript, they
are also known as "expando" properties.
I'm guessing you are looking for indexOf and lastIndexOf.


Nope, string index for arrays is not stringmanipulation. For example:

var Stuff= new Array();
Stuff["Yankees"]=10;
Stuff["Red Sox"]=7;
Stuff["Bagels"]=13;
Stuff["Pizza"]=3;
document.write("<BR>Yankees= " + Stuff['Yankees']);
document.write("<BR>Red Sox= " + Stuff['Red Sox']);
document.write("<BR>Bagels= " + Stuff['Bagels']);
document.write("<BR>Pizza= " + Stuff['Pizza']);


If you got that from the book you mentioned before, I'd mildly suggest
throwing that book away before you learn too much from it. What is
misleading about this code is that you've created an array named Stuff
but it doesn't have any items in it. Try adding a
document.write(Stuff.length) on the end and see how many items are in
the array.

The reason you won't find information on 'string indexes' in
references about Arrays is because the concept has nothing to do with
arrays. They are really properties on an object. You can add any
properties you want to a native Javascript object. An Array is simply
a special type of Object -- which is why the above works -- but if an
object is what you want then an object is what you should use, e.g.:

var Stuff= new Object();
Stuff["Yankees"]=10;
Stuff["Red Sox"]=7;
Stuff.Bagels=13;
Stuff.Pizza=3;

Note the different syntax for accessing the property on the last 2
lines. Either style can be used to access a property except if the
property name contains an invalid character (like the space in Red
Sox) in which case you must use the object[property] form.

Regards,
Steve
Jul 23 '05 #4
"Steve van Dongen" <st*****@hotmail.com> wrote in message
news:nh********************************@4ax.com...
"Howard Kaikow" <ka****@standards.com> wrote:
Highly doubtful. I've never heard the term 'string indexes' before.
Look for information on objects and properties. In MS JScript, they
are also known as "expando" properties.
I too had guessed that they were really objects.
If you got that from the book you mentioned before, I'd mildly suggest
throwing that book away before you learn too much from it.
I would concur.

Several years ago, I purchased the Pure Javascript book and te 3rd edition
of David Fanagan's book.
My recollection is that I thout that DF's book was well done and that the
Pure Javascript book was not at all well done.
What is
misleading about this code is that you've created an array named Stuff
but it doesn't have any items in it. Try adding a
document.write(Stuff.length) on the end and see how many items are in
the array.
Ayup, I did that yesterday and got the expected result of 0.
The reason you won't find information on 'string indexes' in
references about Arrays is because the concept has nothing to do with
arrays. They are really properties on an object.
That's what it looked like to me.
You can add any
properties you want to a native Javascript object. An Array is simply
a special type of Object -- which is why the above works -- but if an
object is what you want then an object is what you should use, e.g.:

var Stuff= new Object();
Stuff["Yankees"]=10;
Stuff["Red Sox"]=7;
Stuff.Bagels=13;
Stuff.Pizza=3;

Note the different syntax for accessing the property on the last 2
lines. Either style can be used to access a property except if the
property name contains an invalid character (like the space in Red
Sox) in which case you must use the object[property] form.


Thanx.
Jul 23 '05 #5
"Steve van Dongen" <st*****@hotmail.com> wrote in message
news:nh********************************@4ax.com...
"Howard Kaikow" <ka****@standards.com> wrote:
I then looked for more info in the 3rd edition of David Flanagan's
Javascript The Definitive Guide. I found no mention of String Indexes.
Is this book out of date?


Highly doubtful. I've never heard the term 'string indexes' before.
Look for information on objects and properties. In MS JScript, they
are also known as "expando" properties.


I see that "expando" is referred to in the 4th edition of David Flanagan's
book, but not in the 3rd edition.

Since I already have the 3rd edition, do I need the 4th edition.

Wonder where MSFT came up with the term "expando"?
Sounds like the name of a villain in a Superman or Batman story.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

108
6293
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
0
2721
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
4
3463
by: Rhonda Tipton | last post by:
Hello. I am trying to do a substring or something like that to extract the middle portion of a string. 12345 TEST FACILITY 1_Letter 1A 12346 TEST FACILITY 2_Letter 1A I would like to be...
4
1580
by: Roshawn | last post by:
Hi, I am retrieving a list of book titles from a web service. What I'd like to do is shorten the titles, if possible. For example, there is a book titled "Malicious Mobile Code: Virus...
4
2982
by: Sjaakie | last post by:
I need to replace parts of a string, in a collection deserialized from an XML file, with values from another collection. Is there another, more clever/faster/better, method than the loops below? ...
1
4541
by: dt | last post by:
My understand is that MYSQL only supports indexes on the beginning of a string of data. for example, if you have a list of email addresses, searching for something like '%@yahoo.com' would need...
4
12709
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or...
5
2300
by: buu | last post by:
I have an function that replaces some string from a huge text that I run very often... So, I wanted to speed it up... I was using String and StringBuilder. But, I was wandering should same...
3
3422
by: banangroda | last post by:
Compilation fails at "line.insert(line.end(), x.begin(), i);" and I can't figure out why. Here is the code: /* 5-1. Design and implement a program to produce a permuted index. A permuted index...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.