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

String.StartsWith("....")

Hi,

I am using lots of string comparisons using
String.StartsWith(subString) method where subString might be more than
just couple of chars (e.g. "This is the string to compare ")

I have noticed that it executes quite slowly. Is there a way to do
this faster?

tx
_dino_
Nov 21 '05 #1
1 2555
"Dino Buljubasic" <di**@noplacelikehome.com> wrote in message news:qe********************************@4ax.com...
I am using lots of string comparisons using
String.StartsWith(subString) method : : Is there a way to do this faster?


You can add all of the subStrings you want to compare against into a SortedList.
Then take the string you're testing and go one-character at a time.

When it starts with 'T', that immediately eliminates most of the subStrings you are
comparing against, narrowing you down to just those strings in the SortedList that
begin with 'T'. When the second character is 'o', that eliminates every string that
starts out like "The" or "Those" or "Tactfully."

Inevitably, you are only checking each character in your string no more than one
time, and you whittle down the number of subStrings you're comparing against
very quickly so there isn't that many comparisons going on.
Derek Harmon
Nov 21 '05 #2

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

Similar topics

32
by: Indrid Colt | last post by:
Thank's for your help ! Indrid
2
by: Joebloggs | last post by:
Hi I am trying to do an ldap lookup. I can pick up the domain name in the standard format DOMAIN\USERNAME. The problem is the company I work for expects the query in the format DOMAIN:USERNAME....
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
1
by: Ducknut | last post by:
Not so much a problem as a discussion. I am currently in the early stages of designing a database to hold a bunch of water quality data (e.g., concentrations of heavy metals in drinking water). Water...
6
by: =?Utf-8?B?SmVmZg==?= | last post by:
I thought this would already be covered here, but my search turned up nothing. In VS2005, if I use "String" to define a new variable/class, it colors it in the Aqua color as it does other...
1
by: dhtmlkitchen | last post by:
Why does "foo" instanceof String return false? It just seems counterintuitive to me. I mean, sure, I can always check the constructor: var fooVar = "foo"; var isString =...
6
by: Warly girl | last post by:
Hi i want your help again in c++ !! i want a function change the "int" to "string" because in my project "Registration system" in task "b" i must write a course class which contains number of...
8
by: rahana | last post by:
hello friends, i have a doubt,what is the difference between String s="Hello" and String s=new String("Hello") please help me.
1
by: mato81 | last post by:
Hi all! I am a newbie to WSDL. I have a questions which has been driving me crazy... If I would have a WSDL with a types element somewhat like below, what is the point of the third last row...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.