I was trying to convert the vb Split() function to C#
and while going through google it seemed pretty much easy but my function is not working or giving me errors.
I went through it more than 30 mins and later found out my mistake that I will
explain in the end of this post.
Ok here is the vb code that uses the split function to split a string line.
Dim strLine As String
strLine = "DataSource = GetDatabase"
lblMsg.Text = getTextLine(strLine)
Public Function getTextLine(ByVal strline As String) As String
Dim spChar As String
spChar = "="
Dim values() As String = Split(line, spChar)
Dim reply As String = values(1).Trim
Return reply
End Function
and the exact replica of this code in C# is :
string strLine;
strLine = "DataSource = GetDatabase";
lblMsg.Text = getTextLine(strLine);
public string getTextLine(string line)
{
char spChar = '=';
string[] arr = line.Split(spChar);
string reply = arr[1];
return reply;
}
Now where i spent my 30 mins making following mistakes:
1. The big mistake what i didn't figure out for long was i did
char spChar= "=";
2. And so I ended up declaring spChar as string. Then the problem worsened.
No comments:
Post a Comment