Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

How to estimate the cost of projects ?

3 Answers   ABB, Voltas,


How would you deal with changes being made a week or so before the ship date?

1 Answers   Microsoft,


Did you used crystal reports? Do you have sufficient knowledge on crystal reports?

0 Answers   HCL,


Please, i am a final year student in nigeria and i have a project on pension fund administration and i need help in starting.

0 Answers  


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.

0 Answers  


How do you estimate the effort for your project? Where is the estimation procedure documented?

4 Answers  


What are the different inputs and outputs of the phases in SDLC ?

7 Answers   Apple, Honeywell,


Write a function that counts the number of primes in the range [1-N]. Write the test cases for this function.

2 Answers   Microsoft,


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

0 Answers   3i Infotech, Choice Solutions, iGate,


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.

0 Answers   Microsoft,


What are the documents that you will refer to create the plan?

1 Answers  


What is DLL HELL?

1 Answers  


Categories