Solved

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

Posted on 2011-03-02
6
726 Views
Last Modified: 2012-05-11
Most omnipotent guru's,
New to c# and vb.net.  I need a very clear cut example of the VB replacement for lResult = instr("DogCatRatBat", "Cat") in c# and vb.net.   I've seen many vb.net/c3 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?

regards,

Ted
0
Comment
Question by:tcalbaz
[X]
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
6 Comments
 
LVL 11

Expert Comment

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

Note: the returned index is  0-based
0
 
LVL 10

Accepted Solution

by:
Jini Jose earned 400 total points
ID: 35019968
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 35019975
wham bam! that was simple.........
0
Technology Partners: 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

by:nepaluz
nepaluz earned 100 total points
ID: 35019984
variation for VB.net

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

(just remove the semicolon)
0
 
LVL 20

Expert Comment

by:informaniac
ID: 35020014
Evrything is simple once you know it. :D
0
 
LVL 1

Author Closing Comment

by:tcalbaz
ID: 35020671
gmailjini - That was a good solution:

Example:
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!!

regards,

Ted
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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