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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / majhoul

int Instr(int start,string string1,string string2,string type-of-the-test)
{

lenght= string2.lenght();
int lenght ;
int i ;// as counter for lenght

if (string1==NULL ll string2==Null)// to check that the
both of the strings
is not empty
return 0;


if (type-of-the-test = "text")// it doesn't matter if it is upper or lower case in the text test !!!
{

string1=toupper(string1) ;
string2=toupper(string2) ;

}



int location = string1.find(string2);



while (location != string::npos)//
{
if (location > start) // the string was found we have to check if it is match the type the test
{

i=0 ;
while ( lenght > 0 )
{

if (string1[location+i]!= string2[i] )
break ;// return where the string was found

}

if ((lenght-1) == i)
return location ;
}

else
location = string1.find(string2,location+1)

}


return 0 ; // if the string wasn't find at all [p


}




' String to search in.
string SearchString = "XXpXXpXXPXXP"
string SearchChar = "P"

TestPos = InStr(4, SearchString, SearchChar,"Text")

' A binary comparison starting at position 1. Returns 9.
TestPos = InStr(1, SearchString, SearchChar,"binary")

//' If Option Compare is not set, or set to Binary, return //9.
//' If Option Compare is set to Text, returns 3.
//TestPos = InStr(SearchString, SearchChar)

//' Returns 0.
//TestPos = InStr(1, SearchString, "W")

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Project Planning Interview Questions

Write the test cases for instr function?

0 Answers  


how to tell project details in interview the project is funds flow analysis?

0 Answers   Mphasis,


What is the team size of your project ?

3 Answers   Infosys, NIIT, Saber Corporation, Satyam,


Explain dll hell?

0 Answers  


Why do you want to work for Microsoft?

0 Answers   Infosys, Microsoft,






How do you track the size or changes to size of the work products in your project?

1 Answers  


Why analysis and testing phases are very important ?

2 Answers   AGR, Infosys,


Test the save dialog in Notepad?

0 Answers   Microsoft,


What is the document that should be consulted to know about your project, the activities you do, your schedules and milestones?

7 Answers  


can any body help me to know the procedure followed by programmer/developer inorder to develop a project. what are the steps, how he/she get the SRS,technical document??how does he submit his wotk to TL/PM/Business Analyst?? How does these documents review?? how the developer starts coding? how does he deploy his coding in server? in which server he will deploy?? what are the important document a developer should have??? Pls give me a real time scenario of development process, how it is going on in a company???? Thanks in advance

1 Answers  


How do speedup the project delivery without affecting the cost?

6 Answers   emc2, HCL,


what is SDLC? what are the different stages in SDLC?

45 Answers   Choice Solutions, College School Exams Tests, HCL, Infosys, SDLC, Soma Enterprises, Wipro,


Categories