Find String

S

shapper

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
 
S

shapper

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


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?

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
 
E

Eliyahu Goldin

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 said:
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


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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,799
Messages
2,569,652
Members
45,385
Latest member
ZapGuardianReviews

Latest Threads

Top