Saturday 5 July 2014

String convert to title case in asp.net

string str="[PRODUCT] IN ('Celerra') AND [PRODUCT_RELEASE] IN ('CFS 7.0') AND [TYPE] IN ('Bug') AND [PRIME_BUG__] IS NULL AND [MAJOR_AREA] OT IN ('EE')";
Replace the value which are located at [] to Title case.
Title case :first letter should be caps rest of them will be small letters..
I tried like ....
Regex reg = new Regex(@"\b[A-Z]\w+");
If we use above one it will convert entire string into Title case.
but i need for [] value only
Solution:
using System.Globalization;
using System.Text.RegularExpressions;
Regex reg = new Regex(@"\[(.*?)\]");
string WhereClause = "jj [jj] kk [kk]";
WhereClause = reg.Replace(WhereClause, delegate(Match m)
{
TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo;
string v = m.ToString();
return textInfo.ToTitleCase(v.ToLower());
});
Response.Write(WhereClause);
=======================================================
To convert a string to proper case we will have to use the System.Globalization namespace.
To do this we will use the following code.
string myString = "raj’s WebSite HaVinG a post oN pRoper cAsE";
TextInfo TI = new CultureInfo("en-US",false).TextInfo;
Response.Write (TI.ToTitleCase( myString ));
[Note: Generally, title casing converts the first character of a word to uppercase and converts the rest of the letters to lowercase.]
=============================
string s = "welcome to title case";Console.WriteLine(Microsoft.VisualBasic.Strings.StrConv(s, VbStrConv.ProperCase,0));
======================================
public static String TCase(String strParam)
{
String strTitleCase = strParam.Substring(0, 1).ToUpper();
strParam = strParam.Substring(1).ToLower();
String strPrev = "";
for (int iIndex = 0; iIndex 1)
{
strPrev = strParam.Substring(iIndex - 1, 1);
}
if (strPrev.Equals(" ") ||
strPrev.Equals("\t") ||
strPrev.Equals("\n") ||
strPrev.Equals("."))
{
strTitleCase += strParam.Substring(iIndex, 1).ToUpper();
}
else
{
strTitleCase += strParam.Substring(iIndex, 1);
}
}
return strTitleCase;
}
==========================================================
string strParam = "hallo nMM [ssD]";
String strTitleCase = strParam.Substring(0, 1).ToUpper();
strParam = strParam.Substring(1).ToLower();
String strPrev = "";
for (int iIndex = 0; iIndex 1)
{
strPrev = strParam.Substring(iIndex - 1, 1);
}
if (strPrev.Equals(" ") ||
strPrev.Equals("\t") ||
strPrev.Equals("\n") ||
strPrev.Equals(".")||
strPrev.Equals("["))
{
strTitleCase += strParam.Substring(iIndex, 1).ToUpper();
}
else
{
strTitleCase += strParam.Substring(iIndex, 1);
}
}
Response.Write(strTitleCase);