473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ 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 2231
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.goo glegroups.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"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
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.goo glegroups.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.goo glegroups.com.. .
On Jun 26, 1:50 pm, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
>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.go oglegroups.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
33672
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 = string.find(file(os.path.join(root,fname), 'rb').read(), 'THIS') print find
8
2136
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
2978
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 problem: In ParamGenerate() I want to find all whitespaces before a certain point in one string. Thus I use the string::find() function. However it seems like this function ignores some whitespaces :/ This is really weird and I need your help. Okay...
3
4436
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*> and use stl find string xyz;
108
6369
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 describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the /start/ and /stop/ indices and the /step/ or stride length of the slice. Missing or out-of-bounds indices are handled in a manner...
4
4740
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 string called str which holds the html code and I want to find the string str1 which would be <img and then write to the list an item that contains all the chars from <img through the > that closes the img tag.
7
17004
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> #include <string> struct abc_struct {
14
22556
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 first occurence. I want to know the positions of both "1234" thanks
1
4210
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: (there is a WORD in ( my string WORD )) and * WORD * to (find WORD) and * WORD * Should give me the to word between star (star ar not part of string)
11
3697
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 be dependant on which string is searched for. On my system, using gcc 4.1.2, I get: pos1=2 problem because pos1=0
0
8732
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
8504
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
7337
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...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
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
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
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
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
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.