Monday, November 8, 2010

Command Line argument + IndexOf() program


Write a program that take a string and a character to be searched from command line input in the string 
and count the occurrence of that character in string and also display the appropriate message.




 //file name is cmd.cs
/* pass string without space in command line argument
*/

using System;
public class cmd{
public static void Main(string []args)
{
string str=args[0];
string s=args[1];
int ind=str.IndexOf(s);
Console.WriteLine("occurrence of {0} in {1} is : {2} ",s,str,ind);
}
}


_________________________________
*+*+*+*+*+*+OUTPUT*+*+*+*+*+*+*+


csc cmd.cs
cmd i_just_want_say_hi h
occurrence of h in i_just_want_say_hi is : 16
__________________________________
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*

No comments:

Post a Comment