How to Change the string to Upper Casing
-
Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!
OK, just to make sure: SOME_TEXT_IN_UPPER_CASE -> SomeTextInUpperCase or SomeTextInUpperCase -> SOME_TEXT_IN_UPPER_CASE? Subject-Line + Content = Not entirely sure what you want.
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!
zxc89 wrote:
I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help..
To just make the string lowercase you can you
string.ToLower()
. But to format it the way you want it, you'd need to write your own algorithm. But it's really easy, if all uppercase strings have the format you mentioned. regards -
OK, just to make sure: SOME_TEXT_IN_UPPER_CASE -> SomeTextInUpperCase or SomeTextInUpperCase -> SOME_TEXT_IN_UPPER_CASE? Subject-Line + Content = Not entirely sure what you want.
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!
You need to use .Split() to divide the original string into a string array (use '_' as the character to split on). Then in each element of the newly created array use the index on the string to get the first letter, then use .SubString to get the remaining characters in the element and make them lower case (.ToLower()), then you can move on to the next element. Use a StringBuilder to concatonate it.
-
Hi Sebastian, i need the following only.. SOME_TEXT_IN_UPPER_CASE -> SomeTextInUpperCase Plz help me to do this one...Thanks..
not elegant but...
private static String mixCase(string inString)
{
String outString = inString.Substring(0, 1).ToUpper();
inString = inString.Substring(1).ToLower();
String lastChar = "";
for (int iIndex = 0; iIndex < inString.Length; iIndex++)
{
if (iIndex > 1)
{
lastChar = inString.Substring(iIndex - 1, 1);
}
if (lastChar.Equals("_"))
{
outString = outString.Substring(0, outString.Length - 1);
outString += inString.Substring(iIndex, 1).ToUpper();
}
else
{
outString += inString.Substring(iIndex, 1);
}
}
return outString;
} -
Hi All, I am using C#.NET. Well I have a string (eg: FILES_NOT_FOUND_AT_ALL). How can i change this string to FilesNotFoundAtAll..Plz Help.. Thanx in Advance!!!
Here's a neat solution. :)
private string Camelize(string text) {
return System.Text.RegularExpressions.Regex.Replace("_" + text, "(_.|.)", delegate(System.Text.RegularExpressions.Match match) { return match.Value.Length == 2 ? match.Value.Substring(1, 1) : match.Value.ToLower(); });
}--- b { font-weight: normal; }
-
not elegant but...
private static String mixCase(string inString)
{
String outString = inString.Substring(0, 1).ToUpper();
inString = inString.Substring(1).ToLower();
String lastChar = "";
for (int iIndex = 0; iIndex < inString.Length; iIndex++)
{
if (iIndex > 1)
{
lastChar = inString.Substring(iIndex - 1, 1);
}
if (lastChar.Equals("_"))
{
outString = outString.Substring(0, outString.Length - 1);
outString += inString.Substring(iIndex, 1).ToUpper();
}
else
{
outString += inString.Substring(iIndex, 1);
}
}
return outString;
}