public static String Lower(String constantString)
{
return constantString.ToLower();
}
2:-Convert String to UpperCase
public static String Upper(String constantString)
{
return constantString.ToUpper();
}
3:- Convert String to proper case
public static String PCase(String constantString)
{
String strProper=constantString.Substring(0,1).ToUpper();
constantString=constantString.Substring(1).ToLower();
String strPrev=string.Empty;
for(int iIndex=0;iIndex < constantString.Length;iIndex++)
{
if(iIndex > 1)
{
strPrev=constantString.Substring(iIndex-1,1);
}
if( strPrev.Equals(" ") ||
strPrev.Equals("\t") ||
strPrev.Equals("\n") ||
strPrev.Equals("."))
{
strProper+=constantString.Substring(iIndex,1).ToUpper();
}
else
{
strProper+=constantString.Substring(iIndex,1);
}
}
return strProper;
}
4- Function to Reverse the String
public static String Reverse(String constantString)
{
if(constantString.Length==1)
{
return constantString;
}
else
{
return Reverse(constantString.Substring(1)) + constantString.Substring(0,1);
}
}
5- Function to Test for Palindrome
public static bool IsPalindrome(String constantString)
{
int stringLength,halfLength;
stringLength=constantString.Length-1;
halfLength=stringLength/2;
for(int iIndex=0;iIndex<=halfLength;iIndex++)
{
if(constantString.Substring(iIndex,1)!=constantString.Substring(stringLength-iIndex,1))
{
return false;
}
}
return true;
}
6- Function to get string from beginning.
public static String Left(String constantString,int iLength)
{
if(iLength>0)
return constantString.Substring(0,iLength);
else
return constantString;
}
7- Function to get string from end
public static String Right(String constantString,int iLength)
{
if(iLength>0)
return constantString.Substring(constantString.Length-iLength,iLength);
else
return constantString;
}
8:-Function to count no.of occurences of Substring in Main string
public static int CharCount(String sourceString,String stringToCount)
{
int count=0;
int position=sourceString.IndexOf(stringToCount);
while(position!=-1)
{
count++;
strSource=sourceString.Substring(position+1);
position=strSource.IndexOf(stringToCount);
}
return count;
}
9:-Convert arrayList to string[]ArrayList subKeysColletion = new ArrayList();
string[] collectionOfSubkeys = new string[subKeysColletion.Count];
collectionOfSubkeys = subKeysColletion.ToArray(typeof(string)) as string[];
0 comments:
Post a Comment