473,785 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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 8252
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(a rsrc)-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,ite m & "|","")
ardest=split(le ft(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.publi c.inetserver.as p.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='jscri pt' 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.publi c.inetserver.as p.general:
Rob Meade wrote on 12 jun 2006 in
microsoft.publi c.inetserver.as p.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='jscri pt' 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.blueyonde r.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
2751
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 = server.createobject("scriptlet.typelib").guid guid=Left(guid,instr(guid,"}")) genguid=guid
2
5769
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 displayed as rows of a table. all i need to do is get the same data into an ASP array to use on the next page, specificaly the +theitem+ and +thenumber+ variables. i can pass any one variable like this: document.writeln('<INPUT TYPE="hidden"...
10
5439
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 of client objects called aClients if I try aClients.RemoveAt I get an error "System.Array" does not contain a definition for "RemoveAt".
7
1871
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 submit button, but when I'm getting the form collection (using post or get (form/querystring) I can't retrieve that
66
4148
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 started by an example from me, that was far from complete and with typing errors, but basically it had the meaning to show that removing controls reversible was the nicest method. This was a lets say conclusion (but what is that in a newsgroup) in a...
10
12213
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 help do the most basic things. One of the "basic" things I haven't been able to find out how to do is how to delete an item from a multidimensional array object and resize it afterwards. It seems so easy to conceive of the code to delete...
9
2590
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 have an input box on each row enabling the user to update the quantity. If the enter a zero I need to remove the item from the array....
6
2052
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 data that was retrieved by the query. At times I may want the display control only to render some items in the set of data returned by SqlDataSource. There would be several scenarios: * render the second data item or third item in to the end...
7
2845
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 to support cloning: Public Class RefClass Public tcp As TcpClient Public name As String End Class Public Class RefClassList Inherits List(Of RefClass) Implements ICloneable
0
10350
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.