Mid Function

Returns the specified portion of a string expression (Mid function), or replaces the portion of a string expression with another string (Mid subroutine).

Σύνταξη:


Mid(string As String, Start As Long [, Length As Long]) As String
Mid([ByRef] string As String, Start As Long, [Length As Long], Text As String)

Επιστρεφόμενη τιμή:

String (only by Function)

Παράμετροι:

string: Any string expression that you want to extract (Mid function). Any text variable name that you want to modify (Mid subroutine).

Start: (Έναρξη) Αριθμητική έκφραση που δείχνει τη θέση του χαρακτήρα μέσα στη συμβολοσειρά, όπου αρχίζει το τμήμα της συμβολοσειράς που θέλετε να αντικαταστήσετε ή να επιστραφεί. Η ελάχιστη επιτρεπόμενη τιμή είναι 1. Η μέγιστη επιτρεπόμενη τιμή είναι 2.147.483.648.

Length: (Μήκος) Η αριθμητική έκφραση που επιστρέφει τον αριθμό των χαρακτήρων που θέλετε να αντικαταστήσετε ή να επιστραφεί. Η μέγιστη επιτρεπόμενη τιμή είναι 2.147.483.648.

Αν παραληφθεί η παράμετρος Length στη Mid function, επιστρέφονται όλοι οι χαρακτήρες στην παράσταση συμβολοσειράς από τη θέση έναρξης ως το τέλος της συμβολοσειράς.

If the Length parameter in the Mid subroutine is less than the length of the text that you want to replace, the text is reduced to the specified length.

Text: The string to replace the string expression (Mid subroutine).

Κωδικοί σφάλματος:

5 Άκυρη κλήση διαδικασίας

Παράδειγμα:


Sub ExampleMid_Function_and_Statement
  text = "This is the original Text"
func1:
  MsgBox Mid(text, 13, 8)   ' returns the word "original"
  MsgBox text               ' text is not modified
stmt1:
  Mid(text, 13, 8, "new")
  MsgBox text               ' returns "This is the new Text"
func2:
  MsgBox Mid(start:=10, string:="The quick brown fox ..") ' shows " brown fox .."
stmt2:
  Mid text, 9, 12, "a new Phrase"
  MsgBox text               ' returns "This is a new Phrase"
End Sub

Παρακαλούμε, υποστηρίξτε μας!