据我了解,Redim 类似于List<T>
. 我可以使用帮助确保从这个 VB6 到 C# 的正确转换:
Private Sub ParseString(sInput As String, sWords() As String, lCount As Long, sDel As String)
' Parses a delimited input string (sInput) on a single
' delimiter and returns the parsed words back in a
' string array sWords().
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' INPUTS:
' sInput - string to be parsed.
' sDel - Delimiter character.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' OUTPUTS:
' sWords() - dynamic string array containing the parsed words.
'
' lCount - long, returning the number of words parsed
'
' NOTES:
' If this subroutine is passed an empty string, it will
' return a lCount of 0 with one element in sWords().
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim lWordStart As Long
Dim lWordEnd As Long
Dim sTemp As String
Dim lParsedArraySize As Long
Dim lDelLen As Long
' Dim lStartM As Long
' Dim lEndM As Long
Dim lLength As Long
lDelLen = Len(sDel)
lLength = Len(sInput)
If sInput = "" Then
ReDim sWords(1 To 1) As String
lCount = 0
sWords(1) = ""
Exit Sub
End If
lParsedArraySize = 50
ReDim sWords(1 To lParsedArraySize) As String
lWordStart = 1
lCount = 1
Do
lWordEnd = InStr(lWordStart, sInput, sDel)
If lWordEnd = 0 Then
sTemp = Mid$(sInput, lWordStart)
If lCount > lParsedArraySize Then
ReDim Preserve sWords(1 To lCount) As String
End If
sWords(lCount) = sTemp
Exit Do
Else
sTemp = Mid$(sInput, lWordStart, lWordEnd - lWordStart)
'If sTemp <> "" Then
If lCount > lParsedArraySize Then
lParsedArraySize = lParsedArraySize + 50
ReDim Preserve sWords(1 To lParsedArraySize) As String
End If
sWords(lCount) = sTemp
lCount = lCount + 1
'End If
lWordStart = lWordEnd + lDelLen
End If
Loop
If lCount < lParsedArraySize Then
ReDim Preserve sWords(1 To lCount) As String
End If
我应该如何将此 If 语句转换为 C#?到目前为止,我已经...
private void ParseString(string sInput, List<string> sWords, int lCount, string sDel)
{
int lWordStart;
int lWordEnd;
string sTemp;
int lParsedArraySize;
int lDelLen;
//int lStartM;
//int lEndM;
int lLength;
lDelLen = sDel.Length;
lLength = sInput.Length;
if(String.IsNullOrEmpty(sInput))
{
}
}