T
Thonglao Rud
Hi all!
I'm new to programming in .NET and I want to convert a function from VB.NET to C#.
[VB.NET - from FxLib]
Public Function ProperCase(ByVal cString As String) As String
'Create the StringBuilder
Dim sb As StringBuilder = New StringBuilder(cString.ToLower())
Dim i As Integer, j As Integer = 0
Dim nLength As Integer = cString.Length
For i = 0 To nLength - 1 Step i + 1
'look for a blank space and once found make the next character to uppercase
If (i = 0) Or (Char.IsWhiteSpace(cString.Chars(i))) Then
'Handle the first character differently
If i = 0 Then
j = i
Else
j = i + 1
End If
'Make the next character uppercase and update the stringBuilder
sb.Remove(j, 1)
sb.Insert(j, Char.ToUpper(cString.Chars(j)))
End If
Next
Return sb.ToString()
End Function
[C# - port by me]
public string ProperCase(string cString)
{
StringBuilder sb = new StringBuilder(cString.ToLower());
int i, j = 0;
int nLength = cString.Length;
for(i = 0; i < nLength; i++)
{
if (i == 0 || Char.IsWhiteSpace(cString))
{
if (i == 0)
j = i;
else
j = i + 1;
sb.Remove(j, 1);
sb.Insert(j, Char.ToUpper(cString));
}
}
return sb.ToString();
}
But when I call it from my application, its result is not correct:
"abc def ghi" --> "Abc ef hi"
Any ideas?
Thank
I'm new to programming in .NET and I want to convert a function from VB.NET to C#.
[VB.NET - from FxLib]
Public Function ProperCase(ByVal cString As String) As String
'Create the StringBuilder
Dim sb As StringBuilder = New StringBuilder(cString.ToLower())
Dim i As Integer, j As Integer = 0
Dim nLength As Integer = cString.Length
For i = 0 To nLength - 1 Step i + 1
'look for a blank space and once found make the next character to uppercase
If (i = 0) Or (Char.IsWhiteSpace(cString.Chars(i))) Then
'Handle the first character differently
If i = 0 Then
j = i
Else
j = i + 1
End If
'Make the next character uppercase and update the stringBuilder
sb.Remove(j, 1)
sb.Insert(j, Char.ToUpper(cString.Chars(j)))
End If
Next
Return sb.ToString()
End Function
[C# - port by me]
public string ProperCase(string cString)
{
StringBuilder sb = new StringBuilder(cString.ToLower());
int i, j = 0;
int nLength = cString.Length;
for(i = 0; i < nLength; i++)
{
if (i == 0 || Char.IsWhiteSpace(cString))
{
if (i == 0)
j = i;
else
j = i + 1;
sb.Remove(j, 1);
sb.Insert(j, Char.ToUpper(cString));
}
}
return sb.ToString();
}
But when I call it from my application, its result is not correct:
"abc def ghi" --> "Abc ef hi"
Any ideas?
Thank