Last post Mar 10, 2014 08:08 PM by David Anton
Mar 10, 2014 04:34 PM|EssCee|LINK
Heres some VB6/ VB .Net code
For iLoop = 0 To Len(BASE) - 1
arrBase(iLoop) = Mid(BASE, iLoop + 1, 1)
I've tried converting it to C# but not getting the correct syntax. My attempt is:
for (iLoop = 0; iLoop <= Strings.Len(BASE) - 1; iLoop++)
arrBase(iLoop) = Strings.Mid(BASE, iLoop + 1, 1);
but get the error arrBase is a variable but used like a method. What would be the correct syntax for C#?
Mar 10, 2014 04:48 PM|UstesG|LINK
try changing arrBase(iLoop) to arrBase[iLoop]
Mar 10, 2014 04:48 PM|dotnetzoom|LINK
There is no Mid function in C#. You should use SubString which is it's equivalent.
for (iLoop = 0; iLoop <= BASE.Length - 1; iLoop++)
arrBase[iLoop] = BASE.SubString(iLoop + 1, 1);
Mar 10, 2014 05:04 PM|Rion Williams|LINK
Give the following a try :
for(int iLoop = 0; iLoop <= BASE.Length - 1; iLoop++)
arrBase[iLoop] = BASE.Substring(iLoop+1, 1);;
Substring is the equivalent of the Mid function within C#.
Mar 10, 2014 08:08 PM|David Anton|LINK
If you're going to use the .NET string methods, then you have to remember that they are 0-based, not 1-based like the VB functions.
So you would need the following:
for (int iLoop = 0; iLoop < BASE.Length; iLoop++)
arrBase(iLoop) = BASE.Substring(iLoop, 1);