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

Better way to search substrings

Hi,

I am currently searching for a collection of substring within a string.

Expand|Select|Wrap|Line Numbers
  1.  if (the_gMap->getCode().containSubstring((String)"MS-VS")==0)
  2.   return True;
  3.  if (the_gMap->getCode().containSubstring((String)"MS-VC")==0)
  4.   return True;
  5.  if (the_gMap->geCode().containSubstring((String)"MS-IP")==0)
  6.   return True;
  7.  if (the_gMap->getCode().containSubstring((String)"MS-OV")==0)
  8.   return True;
  9.  if (the_gMap->getCode().containSubstring((String)"MS-PC")==0)
  10. return True
  11.  
and so on.....
Now can I do this ina more efficient way using a loop. Vectors, arrays, list etc

Please help....
Oct 30 '07 #1
1 1114
Banfa
9,065 Expert Mod 8TB
Create a list of your search strings (or a constant array of strings) and use a loop to iterate through them and check to see if each one is present in turn.
Oct 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
6
by: Alan | last post by:
I want to search a string in a file, but I don't know the position, how can I search the string and stop at that line containing that string ? for example, I want to seach the string ".ABC" in a...
4
by: Robert Dodier | last post by:
Hello all, I'm trying to find substrings that look like 'FOO blah blah blah' in a string. For example give 'blah FOO blah1a blah1b FOO blah2 FOO blah3a blah3b blah3b' I want to get three...
5
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word...
3
by: Girish Sahani | last post by:
Given a length k string,i want to search for 2 substrings (overlap possible) in a list consisting of length k-1 strings. These 2 substrings when 'united' give the original string. e.g given...
8
by: girish | last post by:
Hi, I want to generate all non-empty substrings of a string of length >=2. Also, each substring is to be paired with 'string - substring' part and vice versa. Thus, gives me , , , , , ] etc....
11
by: google | last post by:
I need a simple wildcard pattern matching function written in JS. I have wrestled with regular expresions but frankly am struggling to come up with anything less than an epic function of many lines...
5
by: Kris Kennaway | last post by:
I am trying to parse a bit-stream file format (bzip2) that does not have byte-aligned record boundaries, so I need to do efficient matching of bit substrings at arbitrary bit offsets. Is there a...
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
2
by: Pilcrow | last post by:
This problem was raised in comp.lang.perl.misc, and the poster was concerned, among other things, by the speed of execution. Since C is faster than perl, I wonder how a C coder would solve it? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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 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.