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

C# equilivant of instr()

Jim
What is the equilivant of the VB instr() function? I want to test to see if a string contains a specific character. Code samples would be appreciated. Is there a tutorial on string maniputation using C# in ASP.net ?
Thanks,
Jim
Jul 21 '05 #1
5 188860

String.IndexOf()

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
Hi Jim,

I just had a quick look. You can use the function:
public int IndexOf(
string value,
int startIndex
);

Example:
String str = "hallo world"
int pos = str.IndexOf("wo",0)

* The result would then be 7

Hope the helps

Cheers

Gerhard
"Jim" <an*******@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
What is the equilivant of the VB instr() function? I want to test to see if a string contains a specific character. Code samples would be
appreciated. Is there a tutorial on string maniputation using C# in ASP.net
? Thanks,
Jim

Jul 21 '05 #3
See String::IndexOf

--
Mike J. Deakins
For the shining star in my skies.

"Jim" <an*******@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
What is the equilivant of the VB instr() function? I want to test to see if a string contains a specific character. Code samples would be
appreciated. Is there a tutorial on string maniputation using C# in ASP.net
? Thanks,
Jim

Jul 21 '05 #4
Gerhard,
Example:
String str = "hallo world"
int pos = str.IndexOf("wo",0)

* The result would then be 7


Actually, it would be 6.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #5
Jim <an*******@discussions.microsoft.com> wrote:
What is the equilivant of the VB instr() function? I want to test to
see if a string contains a specific character. Code samples would be
appreciated. Is there a tutorial on string maniputation using C# in
ASP.net ?


The fact that you're using it in ASP.NET is irrelevant - it's just
normal C#/.NET string handling. I believe what you're after here is
String.IndexOf(Char) which will return -1 if the character isn't in the
string.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6

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

Similar topics

5
by: DTB | last post by:
I am trying to convert a complex function from Oracle to SQL Server and have come across Oracle's Instr() function. I see SQL Server has CHARINDEX() which is similar, however it does not provide...
6
by: Chris Calzaretta | last post by:
Hello Everybody, Question instr function will give you the first instance of the finding so EX: so your string looks like string1 = "testing>This is > just a test > testtesttest"...
4
by: Gordon | last post by:
Hi; I am trying to extract a substring using a combination of the mid() and Instr() i.e. aString = "Jones, Thomas R, Dr." hold = InStr(1, aString, " ," , 1) newString = Mid(aString, 1,...
4
by: Jim | last post by:
What is the equilivant of the VB instr() function? I want to test to see if a string contains a specific character. Code samples would be appreciated. Is there a tutorial on string maniputation...
3
by: Mary | last post by:
MemberID VID 1002 1001 1003 1002 1004 1003 1005 1003 1007 1001...
4
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field....
12
by: rodchar | last post by:
hey all, i'm getting a result that i don't understand i have a string "test1, test2" If InStr("test1") and InStr("test2") Then 'Inside EndIf The inside is not running for some reason. Any...
3
by: lstrudeman | last post by:
Hello; A friend gave me this syntax and they are unavailable at the moment and I need this asap. I am trying to figure out how SQL figures this out. Below the syntax takes a field in a file and...
3
by: Alex Pavluck | last post by:
I have a date stored like this '2004 - 2006' and I use this code to get startyear and stopyear StartYear: Trim(Left(,InStr(,"-")-1)) StopYear: Trim(Right(,InStr(,"-")-1)) Is there a way to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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
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...

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.