473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strings as arrays

Safari and FF seem to allow this:

var wiggy = "ABCD";

ch = wiggy[2]; // ch will contain the character 'C'

however my JS book seems to insist that I do this:

ch = wiggy.charAt(2);

and indeed doesn't appear to mention the first method at all.

Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

Thanks,

-- tim
Mar 6 '07 #1
6 2557
On Mar 6, 9:25 am, Tim Streater <tim.strea...@dante.org.ukwrote:
Safari and FF seem to allow this:

var wiggy = "ABCD";

ch = wiggy[2]; // ch will contain the character 'C'

however my JS book seems to insist that I do this:

ch = wiggy.charAt(2);

and indeed doesn't appear to mention the first method at all.

Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

Thanks,

-- tim
Only if you wish to make your application inaccessible to IE users. It
returns [undefined] to them.

Mar 6 '07 #2
Tim Streater wrote:

Hi,
Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?
An excellent one: it is not part of ECMAScript 262, and as such, is not
something browser vendors have to implement.

If you don't want to use the 'chatAt' method, one alternative could be
to transform your string into an array, using the 'split' method.
Kind regards,
Elegie.

Mar 6 '07 #3
In article <45*********************@news.free.fr>,
Elegie <el****@invalid.comwrote:
Tim Streater wrote:

Hi,
Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

An excellent one: it is not part of ECMAScript 262, and as such, is not
something browser vendors have to implement.
Hmm, yes, I rather thought that might be the case, but thanks for
confirming it.
If you don't want to use the 'charAt' method, one alternative could be
to transform your string into an array, using the 'split' method.
I'll probably just stick with charAt. I haven't started implementing
this part of my pages yet, but I want to have something I can treat as
an array while manipulating it, but pass as a single entity between
pages using something like:

document.forms['xxx'].timeslots.value = wiggy;
where I also have:

<form name='xxx'>
<input type=hidden name=timeslots>
</form>
(timeslots will go into a mysql table as char(64)).

-- tim
Mar 6 '07 #4
In article <11*********************@j27g2000cwj.googlegroups. com>,
"Tom Cole" <tc****@gmail.comwrote:
On Mar 6, 9:25 am, Tim Streater <tim.strea...@dante.org.ukwrote:
Safari and FF seem to allow this:

var wiggy = "ABCD";

ch = wiggy[2]; // ch will contain the character 'C'

however my JS book seems to insist that I do this:

ch = wiggy.charAt(2);

and indeed doesn't appear to mention the first method at all.

Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

Thanks,

-- tim

Only if you wish to make your application inaccessible to IE users. It
returns [undefined] to them.
Round here, I'd probably get applause for that :-)

-- tim
Mar 6 '07 #5
Tim Streater wrote:
In article <45*********************@news.free.fr>,
Elegie <el****@invalid.comwrote:

>>Tim Streater wrote:

Hi,

>>>Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

An excellent one: it is not part of ECMAScript 262, and as such, is not
something browser vendors have to implement.


Hmm, yes, I rather thought that might be the case, but thanks for
confirming it.

>>If you don't want to use the 'charAt' method, one alternative could be
to transform your string into an array, using the 'split' method.


I'll probably just stick with charAt. I haven't started implementing
this part of my pages yet, but I want to have something I can treat as
an array while manipulating it, but pass as a single entity between
pages using something like:

document.forms['xxx'].timeslots.value = wiggy;
document.forms['xxx'].timeslots.value = "abc".split("");

Mick
where I also have:

<form name='xxx'>
<input type=hidden name=timeslots>
</form>
(timeslots will go into a mysql table as char(64)).

-- tim
Mar 6 '07 #6
In article <45***********************@roadrunner.com>,
Michael White <mi**@mickweb.comwrote:
Tim Streater wrote:
In article <45*********************@news.free.fr>,
Elegie <el****@invalid.comwrote:

>Tim Streater wrote:

Hi,
Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

An excellent one: it is not part of ECMAScript 262, and as such, is not
something browser vendors have to implement.

Hmm, yes, I rather thought that might be the case, but thanks for
confirming it.

>If you don't want to use the 'charAt' method, one alternative could be
to transform your string into an array, using the 'split' method.

I'll probably just stick with charAt. I haven't started implementing
this part of my pages yet, but I want to have something I can treat as
an array while manipulating it, but pass as a single entity between
pages using something like:

document.forms['xxx'].timeslots.value = wiggy;

document.forms['xxx'].timeslots.value = "abc".split("");

Mick
Mick,

Could you expand on this a little? Is there something actually wrong (in
the sense e.g. that it is non-standard, or some other issue) with it?
What I need is for the hidden variable timeslots in the form below to
get the value of the string wiggy.

Thanks -- tim
where I also have:

<form name='xxx'>
<input type=hidden name=timeslots>
</form>
(timeslots will go into a mysql table as char(64)).

-- tim
-- tim
Mar 7 '07 #7

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

Similar topics

17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
5
by: Robert | last post by:
Hi, Is there some way of using an array of strings? Like in basic? I know you have to create an array of chars so i think it has to be an 2d array or something... Really stuck here... Thanks...
10
by: Ian Todd | last post by:
Hi, I am trying to read in a list of data from a file. Each line has a string in its first column. This is what i want to read. I could start by saying char to read in 1000 lines to the array( i...
2
by: Steve | last post by:
I want an initializer for an array of pointers to arrays of strings. So I can do something like this: const char *t1 = { "a", "b", "c", NULL }; const char *t2 = { "p", "q", NULL }; const char...
1
by: Jeff | last post by:
I am struggling with the following How do I marshal/access a pointer to an array of strings within a structure Than Jef ----------------------------------------------------------------
7
by: Bob Rock | last post by:
Hello, converting from the managed to the unmanaged world (and viceversa strings) and byte arrays is something I do often and I'd like to identify the most correct and efficient way to do it....
6
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an...
23
by: arnuld | last post by:
i was doing exercise 4.3.1 - 4.29 of "C++ Primer 4/e" where authors, with "run-time shown", claim that C++ Library strings are faster than C-style character strings. i wrote the same programme in...
19
by: bowlderyu | last post by:
Hello, all. If a struct contains a character strings, there are two methods to define the struct, one by character array, another by character pointer. E.g, //Program for struct includeing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.