Obtain the sub-string at the specified position in the string. There are many sub-strings that can be accessed in the MIF/Mid file. Therefore, it is easier to write a function. The test passed in VB6 and Delphi7.
' Obtain the substring at the specified position in the string, VB6
' S: string; substr: the specified separator (one character); II: The specified position; getsubstr: The obtained character string
' Eg: getsubstr ("123,456,789,123", 3) returns a string of 789
Public Function Getsubstr (S As String , Substr As String , II As Integer ) As String
Dim Jj As Integer , Tempint As Integer
If Instr ( 1 , S, substr, vbtextcompare) = 0 Then
Getsubstr = ""
Exit Function
End If
Tempint = 1
For Jj = 1 To II
If Instr (Tempint, S, substr, vbtextcompare) = 0 Then
If Jj < II Then
Getsubstr = ""
Else
Getsubstr = Mid (S, tempint, Len (S) - Tempint + 1 )
End If
Exit Function
End If
Getsubstr = Mid (S, tempint, Instr (Tempint, S, substr, vbtextcompare) - Tempint)
Tempint = Instr (Tempint, S, substr, vbtextcompare) + 1
Next Jj
End Function
// Obtain the sub-string in the string, Delphi7
// S: string; substr: the specified separator (one character); index: the specified position; getsubstr: The obtained character string
// Eg: getsubstr ('123', ',', 3) returns the string 123,456,789,123
Function getsubstr (s: String ; Substr: Char; index: integer ): String ;
VaR
Tempstr: String ;
I: integer;
Begin
Tempstr: = S;
If POs (substr, S) = 0 Then result: = ''
Else Begin
Try
For I: = 1 To Index - 1 Do Begin
If POs (substr, tempstr) = 0 Then begin
Result: = '' ;
Exit;
End;
Delete (tempstr, 1 , Pos (substr, tempstr ));
Tempstr: = Trim (tempstr );
End;
Except
Showmessage ( ' Have not such index! ' );
Result: = '' ;
Exit;
End;
If POs (substr, tempstr) = 0 Then
Result: = Tempstr
Else
Result: = Copy (tempstr, 1 , Pos (substr, tempstr) - 1 );
End;
End;