I wanted to convert a column name from the database to a caption.
E.g:
DBType to "DB Type"
ApplicationURL to "Application URL"
This is what i did for it.
C# code
public static string ReturnColumnCaption(String f)
{
string s = "";
char o = '\0';
for (int i = 0; i <= f.Trim().Length - 1; i++)
{
char c = f.Substring(i, 1)[0];
if (char.IsUpper(c))
{
if (char.IsUpper(o))
{
if (i + 1 < f.Trim().Length)
{
char t = f.Substring(i + 1, 1)[0];
if (char.IsUpper(t))
{
s += c;
}
else
{
s += " " + c;
}
}
else
{
s += c;
}
}
else
{
s += " " + c;
}
}
else
{
s += c;
}
o = c;
}
return s.Trim();
}
VB.NET
Private Function ReturnColumnCaption(ByVal f As String) As String
Dim s As String = ""
Dim o As String = ""
For i As Integer = 0 To f.Trim.Length - 1
Dim c As Char = f.Substring(i, 1)
If Char.IsUpper(c) Then
If Char.IsUpper(o) Then
If i + 1 < f.Trim.Length Then
Dim t As Char = f.Substring(i + 1, 1)
If Char.IsUpper(t) Then
s += c
Else
s += " " + c
End If
Else
s += c
End If
Else
s += " " + c
End If
Else
s += c
End If
o = c
Next
Return s.Trim()
End Function
E.g:
DBType to "DB Type"
ApplicationURL to "Application URL"
This is what i did for it.
C# code
public static string ReturnColumnCaption(String f)
{
string s = "";
char o = '\0';
for (int i = 0; i <= f.Trim().Length - 1; i++)
{
char c = f.Substring(i, 1)[0];
if (char.IsUpper(c))
{
if (char.IsUpper(o))
{
if (i + 1 < f.Trim().Length)
{
char t = f.Substring(i + 1, 1)[0];
if (char.IsUpper(t))
{
s += c;
}
else
{
s += " " + c;
}
}
else
{
s += c;
}
}
else
{
s += " " + c;
}
}
else
{
s += c;
}
o = c;
}
return s.Trim();
}
VB.NET
Private Function ReturnColumnCaption(ByVal f As String) As String
Dim s As String = ""
Dim o As String = ""
For i As Integer = 0 To f.Trim.Length - 1
Dim c As Char = f.Substring(i, 1)
If Char.IsUpper(c) Then
If Char.IsUpper(o) Then
If i + 1 < f.Trim.Length Then
Dim t As Char = f.Substring(i + 1, 1)
If Char.IsUpper(t) Then
s += c
Else
s += " " + c
End If
Else
s += c
End If
Else
s += " " + c
End If
Else
s += c
End If
o = c
Next
Return s.Trim()
End Function