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

C# has InList() function?

ABC
Is there any function in C# to do as:

result true if InList('abc,ihjl,dkfd,ooo', 'abc');

Jan 11 '06 #1
5 15506
ABC wrote:
Is there any function in C# to do as:

result true if InList('abc,ihjl,dkfd,ooo', 'abc');


Are you specifically wanting it for that usage? IList has the Contains
method, and Array (which implements IList explicitly) also has IndexOf.
So, you're fine if you've actually already got a list. You can get a
list from a string using string.Split, but for the example you gave it
might be simpler to use:

string x = "abc,ihjl,dkfd,ooo";
if (x.StartsWith("abc") || x.IndexOf(",abc") != -1)
{
...
}

Jon

Jan 11 '06 #2
ABC
Wow,

this method is best. In fact, I don't know it has IList class.

Very Thanks

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
ABC wrote:
Is there any function in C# to do as:

result true if InList('abc,ihjl,dkfd,ooo', 'abc');


Are you specifically wanting it for that usage? IList has the Contains
method, and Array (which implements IList explicitly) also has IndexOf.
So, you're fine if you've actually already got a list. You can get a
list from a string using string.Split, but for the example you gave it
might be simpler to use:

string x = "abc,ihjl,dkfd,ooo";
if (x.StartsWith("abc") || x.IndexOf(",abc") != -1)
{
...
}

Jon

Jan 11 '06 #3
ABC,

I just want to add that the you even don't need to declare a string variable
you can call the methods directly on the string constant like

bool f = "sdasdadasd".IndexOf("dad") != -1;

*f* will be *true* of the string contains the substring.
--

Stoitcho Goutsev (100)

"ABC" <ab*@abc.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
Wow,

this method is best. In fact, I don't know it has IList class.

Very Thanks

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
ABC wrote:
Is there any function in C# to do as:

result true if InList('abc,ihjl,dkfd,ooo', 'abc');


Are you specifically wanting it for that usage? IList has the Contains
method, and Array (which implements IList explicitly) also has IndexOf.
So, you're fine if you've actually already got a list. You can get a
list from a string using string.Split, but for the example you gave it
might be simpler to use:

string x = "abc,ihjl,dkfd,ooo";
if (x.StartsWith("abc") || x.IndexOf(",abc") != -1)
{
...
}

Jon


Jan 11 '06 #4

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
ABC wrote:
Is there any function in C# to do as:

result true if InList('abc,ihjl,dkfd,ooo', 'abc');
Are you specifically wanting it for that usage? IList has the Contains
method, and Array (which implements IList explicitly) also has IndexOf.
So, you're fine if you've actually already got a list. You can get a
list from a string using string.Split, but for the example you gave it
might be simpler to use:

string x = "abc,ihjl,dkfd,ooo";
if (x.StartsWith("abc") || x.IndexOf(",abc") != -1)
{
...
}


Will that fail if x = 'abcd,xxx,yyy,zzz' or x = 'xxx,abcd,yyy', etc? Or am I
just too tired to think of this properly at the moment?

Jon

Jan 11 '06 #5
Tim Bird wrote:
string x = "abc,ihjl,dkfd,ooo";
if (x.StartsWith("abc") || x.IndexOf(",abc") != -1)
{
...
}


Will that fail if x = 'abcd,xxx,yyy,zzz' or x = 'xxx,abcd,yyy', etc? Or am I
just too tired to think of this properly at the moment?


No, you're absolutely right. You potentially want:

if (x.StartsWith("abc,") ||
x.IndexOf(",abc,") != -1 ||
x.EndsWith(",abc") ||
x=="abc")

String.Split would still probably be less efficient, but would be
simpler at that stage :)

Good catch.

Jon

Jan 11 '06 #6

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
6
by: kd | last post by:
Hi All, I found the 'Inlist' function of foxpro very useful. Is there any command in vb.net that does the same job? Thanks. kd
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have 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
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
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.