473,465 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Find String

Hello,

I have two arrays of strings, s1 and s2:

s1 = "london, lisbon, paris, newyork"

s2 = "lisbon, yellow, France"

s2 will have only one item included in s1.

I want to find which item is it. In this case is lisbon.

How can I do this?

Thanks,

Miguel

Jun 26 '07 #1
3 2217
Split one of the string to a string array with the Split() method and then
try to find the array items in another string one by one.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"shapper" <md*****@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
Hello,

I have two arrays of strings, s1 and s2:

s1 = "london, lisbon, paris, newyork"

s2 = "lisbon, yellow, France"

s2 will have only one item included in s1.

I want to find which item is it. In this case is lisbon.

How can I do this?

Thanks,

Miguel

Jun 26 '07 #2
On Jun 26, 1:50 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Split one of the string to a string array with the Split() method and then
try to find the array items in another string one by one.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@p77g2000hsh.googlegr oups.com...
Hello,
I have two arrays of strings, s1 and s2:
s1 = "london, lisbon, paris, newyork"
s2 = "lisbon, yellow, France"
s2 will have only one item included in s1.
I want to find which item is it. In this case is lisbon.
How can I do this?
Thanks,
Miguel
I just made the 2 string arrays using split.
Isn't there a function to get the common elements to the two string
arrays?
I would then get the only value which is common to both string arrays.

Shouldn't this be better than using a for loop and test each string?

Thanks,
Miguel

Jun 26 '07 #3
Not that I know. The foreach loop will consist of only one IndexOf call.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"shapper" <md*****@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
On Jun 26, 1:50 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>Split one of the string to a string array with the Split() method and
then
try to find the array items in another string one by one.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@p77g2000hsh.googleg roups.com...
Hello,
I have two arrays of strings, s1 and s2:
s1 = "london, lisbon, paris, newyork"
s2 = "lisbon, yellow, France"
s2 will have only one item included in s1.
I want to find which item is it. In this case is lisbon.
How can I do this?
Thanks,
Miguel

I just made the 2 string arrays using split.
Isn't there a function to get the common elements to the two string
arrays?
I would then get the only value which is common to both string arrays.

Shouldn't this be better than using a for loop and test each string?

Thanks,
Miguel

Jun 26 '07 #4

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

Similar topics

10
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
8
by: Jaime Wyant | last post by:
Will someone explain this to me? >>> "test".find("") 0 Why is the empty string found at position 0? Thanks! jw
3
by: Chris Mantoulidis | last post by:
I posted this here one day ago but it seems like it hasn't been put up for some unknown reason. That gives me a chance to say things a bit better in this post. 1st of all let's desribe the...
3
by: Prakash Bande | last post by:
Hi, I have bool operator == (xx* obj, const string st). I have declared it as friend of class xx. I am now able to do this: xx ox; string st; if (&ox == st) { } But, when I have a vector<xx*>...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
4
by: KL | last post by:
Hello again, I am still working on this homework assignment and have hit a wall. I have a list that I want to fill with all occurences of img tags from a big string of html code. So I have a...
7
by: tehn.yit.chin | last post by:
I am trying to experiment <algorithm>'s find to search for an item in a vector of struct. My bit of test code is shown below. #include <iostream> #include <vector> #include <algorithm>...
14
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the...
1
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
11
by: Ko van der Sloot | last post by:
Hello I was wondering which behaviour might be expected (or is required) for the following small program. I would expect that find( "a", string::npos ) would return string::npos but is seems to...
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
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
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...
0
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 ...

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.