Very simple question for all you folks out there. I am total noob
with js. I have a list called drawPathList thats just a list of xy
coordinates. I use this to construct a drawing on a map. However,
people would like to be able to 'Undo' something that they have drawn,
so I'd like to yank that last item in a given list.
drawPathList looks like this: 23,34||45,67||456,678||43,78
Can someone help me with a function to remove the last item in the
list (regardless of length)? Thanks all. 15 2845
In article <11********************@k79g2000hse.googlegroups.c om>, bu********@gmail.com wrote:
>Very simple question for all you folks out there. I am total noob with js. I have a list called drawPathList thats just a list of xy coordinates. I use this to construct a drawing on a map. However, people would like to be able to 'Undo' something that they have drawn, so I'd like to yank that last item in a given list.
drawPathList looks like this: 23,34||45,67||456,678||43,78
Can someone help me with a function to remove the last item in the list (regardless of length)? Thanks all.
Seems to me it would make more sense to implement that as an array of strings,
rather than a single string as you appear to have it now. Then deleting the
nth element from an array of n items is trivial.
--
Regards,
Doug Miller (alphageek at milmac dot com)
It's time to throw all their damned tea in the harbor again.
Trivial is the key word here. For now, I think I'm stuck with the
single string, but I'll look at changing how it gets created. If you
have any insight on how to do it with the string, I'd love to hear it.
On Nov 9, 1:07 pm, spamb...@milmac.com (Doug Miller) wrote:
In article <1194630233.307238.6...@k79g2000hse.googlegroups.c om>, buddhat...@gmail.com wrote:
Very simple question for all you folks out there. I am total noob
with js. I have a list called drawPathList thats just a list of xy
coordinates. I use this to construct a drawing on a map. However,
people would like to be able to 'Undo' something that they have drawn,
so I'd like to yank that last item in a given list.
drawPathList looks like this: 23,34||45,67||456,678||43,78
Can someone help me with a function to remove the last item in the
list (regardless of length)? Thanks all.
Seems to me it would make more sense to implement that as an array of strings,
rather than a single string as you appear to have it now. Then deleting the
nth element from an array of n items is trivial.
--
Regards,
Doug Miller (alphageek at milmac dot com)
It's time to throw all their damned tea in the harbor again.
buddhat...@gmail.com wrote:
drawPathList looks like this: 23,34||45,67||456,678||43,78
Can someone help me with a function to remove the last item in
the list (regardless of length)?
The usual code:
var drawPathList = ['23,34', '45,67', '456,678', '43,78'];
drawPathList.pop();
alert(drawPathList);
One-dimensional literal solution using a regular expression:
var drawPathList = '23,34||45,67||456,678||43,78||';
drawPathList = drawPathList.replace(/\|\|(,|\d)+$/ ,'');
alert(drawPathList);
Hope this helps,
--
Bart bu********@gmail.com said the following on 11/9/2007 1:36 PM:
Trivial is the key word here. For now, I think I'm stuck with the
single string, but I'll look at changing how it gets created. If you
have any insight on how to do it with the string, I'd love to hear it.
Quote to learn.
Stuck with a single string? Hmmm.
arrayRef = stringRef.split('||')
What string? Now it is an array. You simply remove/delete the last entry.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Bart Van der Donck wrote on 09 nov 2007 in comp.lang.javascript :
buddhat...@gmail.com wrote:
>drawPathList looks like this: 23,34||45,67||456,678||43,78
Can someone help me with a function to remove the last item in the list (regardless of length)?
The usual code:
var drawPathList = ['23,34', '45,67', '456,678', '43,78'];
drawPathList.pop();
alert(drawPathList);
One-dimensional literal solution using a regular expression:
var drawPathList = '23,34||45,67||456,678||43,78||';
drawPathList = drawPathList.replace(/\|\|(,|\d)+$/ ,'');
alert(drawPathList);
which does not work, as the final || is not detected.
Try:
var x = '23,34||45,67||456,678||43,78||';
x = x.replace(/[,\d]+\|\|$/ ,'');
alert(x);
or
var x = '23,34||45,67||456,678||43,78||';
x = x.split('||');
x.pop();
x.pop();
x.push('');
x = x.join('||');
alert(x);
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Evertjan. wrote:
>buddhat...@gmail.com wrote:
>>drawPathList looks like this: 23,34||45,67||456,678||43,78 Can someone help me with a function to remove the last item in the list (regardless of length)?
>One-dimensional literal solution using a regular expression:
> var drawPathList = '23,34||45,67||456,678||43,78||'; drawPathList = drawPathList.replace(/\|\|(,|\d)+$/ ,''); alert(drawPathList);
which does not work, as the final || is not detected.
Woops, typing mistake (the original poster wrote it without the last
two pipes).
I added it to test * or + before the $.
/\|\|(,|\d)*$/
should also work for '23,34||45,67||456,678||43,78||'.
Try:
var x = '23,34||45,67||456,678||43,78||';
x = x.replace(/[,\d]+\|\|$/ ,'');
alert(x);
This is suitable for my typing mistake, but not for the OP's
question :)
--
Bart
Bart Van der Donck wrote on 09 nov 2007 in comp.lang.javascript :
Evertjan. wrote:
>>buddhat...@gmail.com wrote:
>>>drawPathList looks like this: 23,34||45,67||456,678||43,78 Can someone help me with a function to remove the last item in the list (regardless of length)?
>>One-dimensional literal solution using a regular expression:
>> var drawPathList = '23,34||45,67||456,678||43,78||'; drawPathList = drawPathList.replace(/\|\|(,|\d)+$/ ,''); alert(drawPathList);
which does not work, as the final || is not detected.
Woops, typing mistake (the original poster wrote it without the last
two pipes).
I added it to test * or + before the $.
/\|\|(,|\d)*$/
Ususally writen as:
/\|\|[,\d]*$/
>
should also work for '23,34||45,67||456,678||43,78||'.
>Try:
var x = '23,34||45,67||456,678||43,78||'; x = x.replace(/[,\d]+\|\|$/ ,''); alert(x);
This is suitable for my typing mistake, but not for the OP's
question :)
mmm, yes, I should have seen that, Bart.
So this will do:
var x = '23,34||45,67||456,678||43,78';
x = x.split('||');
x.pop();
x = x.join('||');
alert(x);
or
var x = '23,34||45,67||456,678||43,78';
x = x.replace(/\|\|[,\d]*$/ ,'');
alert(x);
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Randy Webb wrote:
bu********@gmail.com said the following on 11/9/2007 1:36 PM:
>Trivial is the key word here. For now, I think I'm stuck with the single string, but I'll look at changing how it gets created. If you have any insight on how to do it with the string, I'd love to hear it.
Quote to learn.
LOL, YMMD.
Regards,
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Randy Webb wrote:
Stuck with a single string? Hmmm.
arrayRef = stringRef.split('||')
var arrayRef = stringRef.split('||');
What string? Now it is an array. You simply remove/delete the last entry.
var lastElem = arrayRef.pop();
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Thomas 'PointedEars' Lahn said the following on 11/9/2007 3:54 PM:
Randy Webb wrote:
>bu********@gmail.com said the following on 11/9/2007 1:36 PM:
>>Trivial is the key word here. For now, I think I'm stuck with the single string, but I'll look at changing how it gets created. If you have any insight on how to do it with the string, I'd love to hear it.
Quote to learn.
LOL, YMMD.
Top-posting is posting backwards, read the sentence backwards :)
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Thomas 'PointedEars' Lahn said the following on 11/9/2007 3:57 PM:
Randy Webb wrote:
>Stuck with a single string? Hmmm.
arrayRef = stringRef.split('||')
var arrayRef = stringRef.split('||');
That's nice[1].
>What string? Now it is an array. You simply remove/delete the last entry.
var lastElem = arrayRef.pop();
Among other ways.
[1] Need the URL?
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Argh. I omitted something in that original string that I didnt think
would matter, but apparently it does...becasue I cant get any of those
examples to work (but thanks so much for the help)
The string actually looks like this:
var drawPathList = 'm 23,34||45,67||456,678||43,78';
note the m in the beginning and no || at the end. bu********@gmail.com said the following on 11/10/2007 10:22 PM:
Argh. I omitted something in that original string that I didnt think
would matter, but apparently it does...becasue I cant get any of those
examples to work (but thanks so much for the help)
You also forgot to quote what you are replying to.
The string actually looks like this:
var drawPathList = 'm 23,34||45,67||456,678||43,78';
note the m in the beginning and no || at the end.
The m and || don't matter to split. If the solution posted by Evertjan
isn't "working" then something else in your code is causing the problem
Post a URL to a sample page.
But, there is a solution without using arrays at all.
var oldList = 'm 23,34||45,67||456,678||43,78';
var newList = oldList.substring(0,oldList.lastIndexOf('||'));
alert(newList);
gives
m 23,34||45,67||456,678
Which is what you wanted, isn't it?
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Wow. I am embarrassed. Code works fine now. The | were actually
l's. I dont recall ever seeing something delimited with an l...but I
suppose it could make sense since its a line coord. Anyway, thanks to
everyone for the help. My appreciated.
Jason
On Nov 10, 11:19 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
buddhat...@gmail.com said the following on 11/10/2007 10:22 PM:
Argh. I omitted something in that original string that I didnt think
would matter, but apparently it does...becasue I cant get any of those
examples to work (but thanks so much for the help)
You also forgot to quote what you are replying to.
The string actually looks like this:
var drawPathList = 'm 23,34||45,67||456,678||43,78';
note the m in the beginning and no || at the end.
The m and || don't matter to split. If the solution posted by Evertjan
isn't "working" then something else in your code is causing the problem
Post a URL to a sample page.
But, there is a solution without using arrays at all.
var oldList = 'm 23,34||45,67||456,678||43,78';
var newList = oldList.substring(0,oldList.lastIndexOf('||'));
alert(newList);
gives
m 23,34||45,67||456,678
Which is what you wanted, isn't it?
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
wrote on 12 nov 2007 in comp.lang.javascript :
Wow. I am embarrassed.
Even so:
[Please do not toppost on usenet]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: amiga500 |
last post by:
Hello,
I have one basic simple question. When I have multiple records in the
datagrid as follows:
Code Product 1 Product 2 Product 3
11111 A B C...
|
by: yufufi |
last post by:
Hello,
How does delete know how much memory to deallocate from the given
pointer? AFAIK this informations is put there by new. new puts the
size of the allocated memory before the just before...
|
by: ITAutobot25 |
last post by:
My delete button is not working in my GUI and my due date is today before midnight. Can anyone show me how to correct this error? My assignment statement is below as well as 5 classes. InventoryGUI...
|
by: TBass |
last post by:
Hi,
Switching some code from C to C++, and I have a destructor question:
In the C code, when the program wants to close and free all memory, I
have them call a Close function. The linked-lists...
|
by: Ratko |
last post by:
Say you have something like this:
for item in myList:
del item
Would this actually delete the item from the list or just decrement
the reference counter because the item in myList is not...
| |
by: dudeja.rajat |
last post by:
Hi,
I've a list some of whose elements with character \.
I want to delete this last character from the elements that have this
character set at their end,
I have written a small program,...
|
by: dudeja.rajat |
last post by:
Sorry : Earlier mail had a typo in Subject line which might look
in-appropriate to my friends
Hi,
I've a list some of whose elements with character \.
I want to delete this last character...
|
by: Fredrik Lundh |
last post by:
dudeja.rajat@gmail.com wrote:
explicitly comparing against true is bad style; better write that as
if item.endswith('\\'):
item.endswith("\\") works just fine:
|
by: norseman |
last post by:
dudeja.rajat@gmail.com wrote:
==============================
depending on OS and other factors, the DirList may be more like:
ABDIR\ 41 42 44 49 52 5C 0A
nextDir
If so endswith needs to...
|
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,...
|
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,...
| |
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...
|
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...
|
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: 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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |