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

optimize the method

Hi,
I was wondering if there is a better way to do this....
This is my example....
Dim x as String()
dim y as string
dim i as string

y="tree;bush;plant;grass"
x = y.split(cchar(";"),y)
i= "house"
if i = x().? then
'do something
end if
Basically is there a way in dotnet to look into the arraylist for i without
looping through each y?

Thanks,
Brian
Aug 25 '08 #1
6 899
You can use the fact that y will start with "house;", end with ";house", or
contain ";house;". Test that with StartsWith, EndsWith, or IndexOf.

"Brian" wrote:
Hi,
I was wondering if there is a better way to do this....
This is my example....
Dim x as String()
dim y as string
dim i as string

y="tree;bush;plant;grass"
x = y.split(cchar(";"),y)
i= "house"
if i = x().? then
'do something
end if
Basically is there a way in dotnet to look into the arraylist for i without
looping through each y?

Thanks,
Brian
Aug 25 '08 #2
Once you split string using ";" convet it into Stack and then you can search
for any string. This would be faster too.

Mayur
"Brian" <bs********@community.nospamwrote in message
news:uS**************@TK2MSFTNGP04.phx.gbl...
Hi,
I was wondering if there is a better way to do this....
This is my example....
Dim x as String()
dim y as string
dim i as string

y="tree;bush;plant;grass"
x = y.split(cchar(";"),y)
i= "house"
if i = x().? then
'do something
end if
Basically is there a way in dotnet to look into the arraylist for i
without looping through each y?

Thanks,
Brian


Aug 25 '08 #3
what do you mean covert into stack?

"Mayur H Chauhan" <ma***@orioninc.comwrote in message
news:e0****************@TK2MSFTNGP03.phx.gbl...
Once you split string using ";" convet it into Stack and then you can
search for any string. This would be faster too.

Mayur
"Brian" <bs********@community.nospamwrote in message
news:uS**************@TK2MSFTNGP04.phx.gbl...
>Hi,
I was wondering if there is a better way to do this....
This is my example....
Dim x as String()
dim y as string
dim i as string

y="tree;bush;plant;grass"
x = y.split(cchar(";"),y)
i= "house"
if i = x().? then
'do something
end if
Basically is there a way in dotnet to look into the arraylist for i
without looping through each y?

Thanks,
Brian



Aug 25 '08 #4
I am sorry for my mistake. Instead of Stack, you can have List. Here is an
example

Dim s As String = "1;2"

Dim r = s.Split(";"c).ToList()

If r.Contains("1") = True Then

Else

End If


"Brian" <bs********@community.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
what do you mean covert into stack?

"Mayur H Chauhan" <ma***@orioninc.comwrote in message
news:e0****************@TK2MSFTNGP03.phx.gbl...
>Once you split string using ";" convet it into Stack and then you can
search for any string. This would be faster too.

Mayur
"Brian" <bs********@community.nospamwrote in message
news:uS**************@TK2MSFTNGP04.phx.gbl...
>>Hi,
I was wondering if there is a better way to do this....
This is my example....
Dim x as String()
dim y as string
dim i as string

y="tree;bush;plant;grass"
x = y.split(cchar(";"),y)
i= "house"
if i = x().? then
'do something
end if
Basically is there a way in dotnet to look into the arraylist for i
without looping through each y?

Thanks,
Brian




Aug 25 '08 #5
Brian wrote:
Hi,
I was wondering if there is a better way to do this....
This is my example....
Dim x as String()
dim y as string
dim i as string

y="tree;bush;plant;grass"
x = y.split(cchar(";"),y)
i= "house"
if i = x().? then
'do something
end if
Basically is there a way in dotnet to look into the arraylist for i without
looping through each y?

Thanks,
Brian

Once you have split the data into an array, there is no way of searching
for a string in the array without looping. There are several different
ways that you can search the array, but there is no method that can do
it without looping the array.

As Mike suggested, you should search the string without splitting it.

You can use a regular expression:

If RegEx.Match("(^|;)"+RegEx.Escape("house")+"(;|$)") .Success Then

--
Göran Andersson
_____
http://www.guffa.com
Aug 26 '08 #6
Brian wrote:
I was wondering if there is a better way to do this....
y="tree;bush;plant;grass"
x = y.split(cchar(";"),y)
i= "house"
if i = x().? then
'do something
end if
Basically is there a way in dotnet to look into the arraylist for i without
looping through each y?
If you really mean "look into the /ArrayList/", then yes - ArrayList has
a Contains method:

x = New ArrayList
x.Add( tree" )
.. . .
x.Add( grass" )

Dim i as String = "house"
If x.Contains( i ) Then
. . .
End If

HTH,
Phill W.
Aug 26 '08 #7

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

Similar topics

0
by: Tom Paquette | last post by:
Hi, Having made very good use of the ADO recordset Field indexes created by setting the Optimize property, I am thrashing through ADO.Net literature to identify the same functionality. Being...
0
by: Andreas Falck | last post by:
Hi, I ran the code below on two different versions, 4.0.14 and 4.0.16 respectively, both running RH 7.3 on intel. In version mysql server version 4.0.14 the SELECT privelege suffices for...
9
by: Julie | last post by:
Due to circumstances beyond my immediate control, I've been put in charge of getting some JavaScript code in place and operational ASAP. Normally, I'm a C++ programmer, and previously have only...
0
by: Daniel | last post by:
Hi there, I recently came across an interesting option when right clicking on a project (Right click on the project -> properties -> Configuration Properties ->Build -> Optimize) There is an...
6
by: Silly | last post by:
byte Name = new byte; uint len = (uint)Name.Length; uint err = MyFunction(devID, out Name, out len); When this code is run in release build with optimize code set to true, len is evaluated to...
3
by: Reddy | last post by:
The sql query for my datagrid returns 100, 000 records. But the datagrid should display 20 records per page. I am using datagrid paging, but it is taking too much time for the page to load. Is...
6
by: Steeve | last post by:
Hi, Is this possible to optimize this method ? It's the method than I call most offen in my application (result of Sampling Profiling in Visual Studio Performance report) I use this method to...
15
by: kenneth | last post by:
I was trying to use multiple thread to optimize my following code, but met some problems, anyone can help me? k are initialized. int computePot() { int i, j; for( i=0; i<500; i++ ) { for(...
5
by: timor.super | last post by:
Hi group, imagine I want to find number of values of a word in a string ... Look at my code : List<stringthingsToFind = new List<string>(new string {"error", "values"}); MyClass myClass =...
2
by: bsagert | last post by:
I wrote my own feed reader using feedparser.py but it takes about 14 seconds to process 7 feeds (on a windows box), which seems slow on my DSL line. Does anyone see how I can optimize the script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.