473,324 Members | 1,678 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,324 software developers and data experts.

[ASP] Arrays - removing an item?

Hi all,

I have an array of lets say 10 items, I now want to remove an item, lets say
from somewhere in the middle, based on one of the element values equalling a
value I specify - is there a "clever" and "quick" way of doing this or, will
I need to iterate through it looking for a match, and build another array
where I dont find the match etc...

Any advice appreciated..

Regards

Rob
Jun 12 '06 #1
9 8131
Rob Meade wrote:
Hi all,

I have an array of lets say 10 items, I now want to remove an item,
lets say from somewhere in the middle, based on one of the element
values equalling a value I specify - is there a "clever" and "quick"
way of doing this
nope
or, will I need to iterate through it looking for a
match, and build another array where I dont find the match etc...

yup

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 12 '06 #2
"Bob Barrows [MVP]" wrote ...
nope
yup


LOL..

Thanks Bob - I've been doing this for 2 hours now and its driving me bl**dy
crazy....I've hitting some response writes to prove I'm in a section of code
where it should be redim'ing preserving the temp array and resizing it
etc....it doesn't seem to be growing, so I changed the increment to 10 and
still it comes out with a response.write UBound(myArray, 2) as 1 - I mean -
WHAT THE HELL!!!

arrghhhh....

:o(
Jun 12 '06 #3
Rob Meade wrote:
"Bob Barrows [MVP]" wrote ...
nope
yup


LOL..

Thanks Bob - I've been doing this for 2 hours now and its driving me
bl**dy crazy....I've hitting some response writes to prove I'm in a
section of code where it should be redim'ing preserving the temp
array and resizing it etc....it doesn't seem to be growing, so I
changed the increment to 10 and still it comes out with a
response.write UBound(myArray, 2) as 1 - I mean - WHAT THE HELL!!!

arrghhhh....

Are you using a dynamic array? Do you know how many items you'll be
removing? if so, why not initially redim the array to the intended size?
repeated "redim preserve"s is not very efficient. Actually, I've just
had a brainstorm for a quicker way to do it. Here is some code
illustrating both ways to remove a single item from an array:
<%
option explicit
dim ar
ar=array("a","b","c")
response.write join(ar,", ") & "<BR>"
ar=remove(ar,"b")
response.write join(ar,", ")
ar=array("a","b","c")
response.write "<BR>" & join(ar,", ") & "<BR>"
ar=remove2(ar,"c")
response.write join(ar,", ")
'-------------------------------------------
function remove(byval arsrc,item)
dim ardest(), i, j, curitem
redim ardest(ubound(arsrc)-1)
j=0
for i = 0 to ubound(arsrc)
curitem=arsrc(i)
if curitem<>item then
ardest(j) = curitem
j=j+1
end if
next
remove=ardest
end function

'-------------------------------------------
function remove2(byval arsrc,item)
dim s, ardest
s=join(arsrc,"|") & "|"
s=replace(s,item & "|","")
ardest=split(left(s,len(s)-1),"|")
remove2=ardest
end function
%>


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 12 '06 #4
Rob Meade wrote on 12 jun 2006 in
microsoft.public.inetserver.asp.general:
Hi all,

I have an array of lets say 10 items, I now want to remove an item,
lets say from somewhere in the middle, based on one of the element
values equalling a value I specify - is there a "clever" and "quick"
way of doing this or, will I need to iterate through it looking for a
match, and build another array where I dont find the match etc...

Any advice appreciated..


<script language='jscript' runat='server'>

a = ["a","b","c"]

a[1] = null

a = a.join('-').replace(/\-\-/g,'-').split('-')

alert(a)
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 12 '06 #5
Evertjan. wrote on 13 jun 2006 in microsoft.public.inetserver.asp.general:
Rob Meade wrote on 12 jun 2006 in
microsoft.public.inetserver.asp.general:
Hi all,

I have an array of lets say 10 items, I now want to remove an item,
lets say from somewhere in the middle, based on one of the element
values equalling a value I specify - is there a "clever" and "quick"
way of doing this or, will I need to iterate through it looking for a
match, and build another array where I dont find the match etc...

Any advice appreciated..
<script language='jscript' runat='server'>

a = ["a","b","c"]

a[1] = null

a = a.join('-').replace(/\-\-/g,'-').split('-')


alert(a)
I mean:

response.write(a.split(','));


</script>


If your Q was about ASP-vbscript only please specify.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 12 '06 #6

"Rob Meade" <te*********************@edaem.bbor> wrote in message
news:fO******************@text.news.blueyonder.co. uk...
Hi all,

I have an array of lets say 10 items, I now want to remove an item, lets
say from somewhere in the middle, based on one of the element values
equalling a value I specify - is there a "clever" and "quick" way of doing
this or, will I need to iterate through it looking for a match, and build
another array where I dont find the match etc...

Any advice appreciated..


Why dont you just use the Dictionary object unless the array needs to be
stored in the session, then you'd better not do that.

(Never store objects in the session in classic ASP)

--
compatible web farm Session replacement for Asp and Asp.Net
http://www.nieropwebconsult.nl/asp_session_manager.htm

Jun 13 '06 #7
"Egbert Nierop (MVP for IIS)" wrote ...
Why dont you just use the Dictionary object unless the array needs to be
stored in the session, then you'd better not do that.


Hi Egbert,

Thanks for the reply - alas I am using Sessions as I need to store the
basket contents for an eCommerce solution.

Regards

Rob
Jun 13 '06 #8
"Evertjan." wrote ...
If your Q was about ASP-vbscript only please specify.


It was - my apologies.

Regards

Rob
Jun 13 '06 #9
"Bob Barrows [MVP]" wrote ...

[snip example]

Hi Bob,

Thanks for the reply - and example - I managed to get it working but I will
give your example a whirl shortly as I suspect its a bit better than mine
:o)

Regards

Rob
Jun 13 '06 #10

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

Similar topics

6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
2
by: bunnyman | last post by:
I have a for each loop in javascript, of which I need to output to an ASP array. unfortunantly not too familiar with javascript.. the loop is for items ordered in a shopping cart. they are...
10
by: Liz - Newbie | last post by:
Does anyone know how to clear arrays? My C# books talk about creating arrays or talk about using Clear or RemoveAt but these methods don't appear to be available for my array. I have an array...
7
by: Bruno Alexandre | last post by:
Hi guys, Sorry about the off topic, but I can't find the ASP group just the ASP dot NET If I want to block a user to change a form after submiting, I add a function that will disable the...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
9
by: Rob Meade | last post by:
Hi all, Ok - so I've got the array thing going on, and the session thing going on, and up until now its all been ok. I've got my view basket page which is displaying 3 rows (as an example) - I...
6
by: Ken Fine | last post by:
I'm using SQLDataSource, which generates some kind of dataset, and then I attach that datasource to various data display controls such as DataList and repeater which loop through to the end of the...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.