Reputation: 418
what would be its c# equivalent code
Dim arLines() As String
Dim int i
arLines = Split(RTB1.Text, vbNewLine)
For i = 0 To UBound(arLines)
''# RTB2.Text = arLines(i)
Next i
Upvotes: 1
Views: 6165
Reputation: 124770
string[] arLines;
arLines = RTB1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
for( int i = 0; i < arLines.Length; ++i )
{
RTB2.Text = arLines[i];
}
That's done, but your code just wipes out the Text property of RTB2 each iteration (I'm assuming it is not supposed to be commented out as it is in your example), so you may as well just do this:
string[] arLines;
arLines = RTB1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
RTB2.Text = arLines[arLines.Length-1];
Upvotes: 4
Reputation: 47417
The reason the online tools didn't help you was because you weren't sending valid VB in the first place.
Dim int i ''# will not compile
You need
Dim i As Integer ''# This will compile
Here's the C# equivalent
string arLines = null;
int i = 0;
arLines = Strings.Split(RTB1.Text, Constants.vbNewLine);
for (i = 0; i <= Information.UBound(arLines); i++) {
RTB2.Text = arLines(i);
}
However, the code above (a direct VB to C# translation) isn't going to be much help for you either since RTB2.Text will simply be the LAST iteration of your for loop.
A great translation tool is found at
http://converter.telerik.com
Upvotes: 4
Reputation: 20860
There is a good translator at Developer Fusion - http://www.developerfusion.com/tools/convert/vb-to-csharp/
I've tried translating your code but the translator only works if your code compiles to start with (this is always an excellent place to start!). See suggestion from @rockinthesixstring :)
Upvotes: 2