Retorna a posição da ocorrência de uma string em outra, a partir do término da string.
Sintaxe
InStrRev(string1, string2[, start[, compare]])
Argumentos:
Tabela 11-17 Constantes de Comparação e Descrições
| Constante | Valor | Descrição |
|---|---|---|
vbBinaryCompare |
0 | Executa uma comparação binária |
vbTextCompare |
1 | Executa uma comparação textual |
Valor de Retorno
A função InStrRev retorna os seguintes valores:
Tabela 11-18 Valores de Retorno da Função InstrRev
| Se | InstrRev Retornará |
|---|---|
| a string1 tiver tamanho zero | 0 |
| a string2 tiver tamanho zero | Start |
| a string2 não for encontrada | 0 |
| a string2 for encontrada na string1 | Posição na qual a correspondência foi encontrada. |
| start > Len(string2) | 0 |
Comentários
Os exemplos a seguir usam a função InStrRev para pesquisar uma string:
Exemplo 1:
Dim SearchString, SearchChar, MyPos SearchString ="abcdABCD" ' String to search in. SearchChar = "a" ' Search for "a" MyPos = InstrRev(SearchString, SearchChar) ' Default Comparison is binary and starting at the last position (Third and Fourth argument is omitted) 'Output: 1
Exemplo 2:
Dim SearchString, SearchChar, MyPos SearchString ="XXpXXpXXPXXP" ' String to search in. SearchChar = "P" ' Search for "P". MyPos = InstrRev(SearchString, SearchChar, 8) ' Comparison is binary by default (last argument is omitted). 'Output: 0
Exemplo 3:
Dim SearchString, SearchChar, MyPos SearchString ="XXpXXpXXPXXP" ' String to search in. SearchChar = "P" ' Search for "P". MyPos = InstrRev(SearchString, SearchChar, 10, 0) ' A binary comparison starting at position 10. 'Output: 9 MyPos = InstrRev(SearchString, SearchChar, -1, 1) ' A textual comparison starting at the last position. 'Output: 12
Exemplo 4:
Dim SearchString, SearchChar, MyPos SearchString ="abcdABCD" ' String to search in. SearchChar = "a" ' Search for "a" MyPos = InstrRev(SearchString, SearchChar, -1, 0) ' A binary comparison starting at the last position. 'Output: 1 MyPos = InstrRev(SearchString, SearchChar, -1, 1) ' A textual comparison starting at the last position. 'Output: 5
Nota:
A sintaxe da função InStrRev não é a mesma da função InStr.