public static string ProperCase(string strValue) { // Convert the 1st Char in the String to UpperCase and // store it in our return string. string strProper = strValue.Substring(0,1).ToUpper(); // Convert the Rest of the String to LowerCase and // over write the original string strValue = strValue.Substring(1).ToLower(); string strPrev = ""; for(int intIndex=0; intIndex{ if(intIndex>1) { //put the Previous Char in strPrev strPrev = strValue.Substring(intIndex-1, 1); } //Search for White Space or Tab or new line or Dot in the strPrev, // that is mean new word starts with UpperCase if( strPrev.Equals(" ") || strPrev.Equals("\t") || strPrev.Equals("\n") || strPrev.Equals(".") ) { //new word means 1st char convert to UpperCase strProper += strValue.Substring(intIndex, 1).ToUpper(); } else { //No New word so take on Char and add it to the strProper. strProper += strValue.Substring(intIndex, 1); } } return strProper; }
public static string Reverse(string strValue) { // this is the Termination of the Recursion when the string // length is 1 means on char if(strValue.Length==1) { return strValue; } else { //print the or store the 1st char every time, //so that when 1st Char stored will be the end of the string //this way the string will be reversed return Reverse( strValue.Substring(1) ) + strValue.Substring(0,1); } }
public static int CharCount(string strSource,string strCountString) { int intCount = 0; //Find the Position of the 1st Match int intPos = strSource.IndexOf(strCountString); while(intPos != -1) { //Increase Count intCount++; //Update the Original String strSource = strSource.Substring(intPos+1); //Find the next Match intPos = strSource.IndexOf(strCountString); } return intCount; }
public static bool IsPalindrome(string strValue) { int intLen, intStrPartLen; intLen = strValue.Length - 1; //Cut the length of the string into 2 halfs intStrPartLen = intLen / 2; for(int intIndex = 0; intIndex <= intStrPartLen; intIndex++) { //intIndex is the index of the char in the front of the string //Check from behind and front for match if(strValue[intIndex] != strValue[intLen]) { return false; } //decrease the lenght of the original string to //test the next Char from behind intLen--; } return true; }
//this my namespace I made using CStringLib;
public class CString { string myString; public CString(string str) { myString = str; } //this method will cut the string from left to the specified Length public string Left(int intLen) { if(intLen > 0) { string strTemp = myString.Substring(0, intLen); return strTemp } else { return myString; } } }
// this way you create an object of your class CString myCString = "Hello World"; //this way you can call your methods myCString = myCString.Left(4);
Build Your Own ASP.NET Website Using C# & VB.NET