Ative o JavaScript no navegador para exibir as páginas da Ajuda do LibreOfficeDev.

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).

Sintaxe:


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)

Valor de retorno:

String (somente por Function)

Parâmetros:

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

Start: Expressão numérica que indica a posição do caractere dentro da string onde começa a parte da string a substituir ou retornar. O valor mínimo permitido é 1. O valor máximo permitido é 2.147.483.648.

Length: Expressão numérica que retorna o número de caracteres a substituir ou retornar. O valor máximo permitido é 2.147.483.648.

Se o parâmetro Length da função Mid for omitido, serão retornados todos os caracteres da expressão de cadeia de caracteres, da posição inicial até a posição final.

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).

Códigos de erro:

5 Chamada de procedimento inválida

Exemplo:


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