Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


replacement function for "Result = instr("DogCatRatBat", "Cat") " in c# and

Posted on 2011-03-02
Medium Priority
Last Modified: 2012-05-11
Most omnipotent guru's,
New to c# and  I need a very clear cut example of the VB replacement for lResult = instr("DogCatRatBat", "Cat") in c# and   I've seen many semi-examples that feature looking for a single character and returning the ordinal position.  But I haven't found anything that simply returns the location of a simple multi-character substring within a string.  Can someone post a clear and complete example of what I need to have?


Question by:tcalbaz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Expert Comment

ID: 35019959
lResult = "DogCatRatBat".IndexOf("Cat");

Note: the returned index is  0-based
LVL 10

Accepted Solution

Jini Jose earned 1600 total points
ID: 35019968
LVL 17

Expert Comment

ID: 35019975
wham bam! that was simple.........
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 17

Assisted Solution

nepaluz earned 400 total points
ID: 35019984
variation for

Dim lResult = "DogCatRatBat".IndexOf("Cat")

(just remove the semicolon)
LVL 20

Expert Comment

ID: 35020014
Evrything is simple once you know it. :D

Author Closing Comment

ID: 35020671
gmailjini - That was a good solution:

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

* The result would then be 7

nepuluz - I give you partial credit since you answered with in 3 minutes of gmailjini and your solution is so intriquing.

Thank you both!!



Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question