Write the InStr function. Write the test cases for this
function?

Answer Posted / echo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InStr
{
class Program
{
static void Main(string[] args)
{
//test case 1, should return -1
string txt = "this is a test";
string searchString = "ae";
Console.WriteLine(InStr(txt, searchString));


//cast case 2, should return 2
txt = "this is a test";
searchString = "is";
Console.WriteLine(InStr(txt, searchString));

Console.Read();
}

//return the position of the first occurrence of one
string "searchString" within another "txt"
//return -1 means cannot find
static int InStr(string txt, string searchString)
{
return txt.IndexOf(searchString);
}
}
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you rate yourself in c#,vb.net,Asp.net,oracle,sql server ?

4972


How are the team members kept informed about the current status of the project?

2179


Given a MAKEFILE (yeah a makefile), design the data structure that a parser would create and then write code that iterates over that data structure executing commands if needed.

5172


When you come in to the office, how do you know what you have to do during the day?

1929


Write the instr function.

743






How do you create the Software Project Management Plan (SPMP)?

4043


Explain the various activities you do (as a PL) when the project is started up.

2368


How did you choose the appropriate lifecycle for your project?

2888


Why do you want to work for Microsoft?

2715


What is the project management structure in your project? Is a PL assigned to the project?

2039


Can any one please give me an effective format for designing a functional specification and technical specification sheet for a software developemnt related company asap...it would be highly useful for my final year project.

2446


Explain dll hell?

667


What training have you undergone in project planning?

3329


Tell about current project ?

2214


Write the test cases for instr function?

648