Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Ajuda do Scilab >> Cadeias de Caracteres (Strings) > strindex

strindex

procura posição de um string em outro

Seqüência de Chamamento

ind=strindex(haystack,needle,[flag])
[ind,which]=strindex(haystack,needle,[flag])

Parâmetros

haystack

string. O string onde se procurará por ocorrências de needle

needle

string ou vetor de strings . O(s) string(s) a serem procurados em haystack

ind

vetor de índices

which

vetor de índices

flag

string ("r" para expressão regular)

Descrição

strindex procura índices onde needle (i) é encontrado em haystack

Para cada k existe um i tal que part(haystack,ind(k)+(0:length(needle(i))-1)) é o mesmo string que needle(i). Se o argumento which for requerido, ele contém esses i. Quando se usa o terceiro parâmetro "r", needle deve ser um string de expressão regular. Então, strindex irá corresponder a haystack de acordo com as regras regulares expressas.

strindex sem expressão regular é baseado no algoritmo de Knuth-Morris-Pratt.

Este algoritmo é mais poderoso que aquele usado no Scilab 4.x. Em alguns casos especiais, o resultado pode ser diferente.

Exemplo:

// Scilab 5.x

-->[k,w]=strindex('aab',['a','ab'])

w = 1. 1. 2. k = 1. 2. 2.

// scilab 4.x

-->[k,w]=strindex('aab',['a','ab'])

w = 1. 1. k = 1. 2.

As regras de expressão regular são similares às da linguagem Perl. Para uma introdução rápida , ver http://perldoc.perl.org/perlrequick.html. Para um tutorial mais profundo , ver http://perldoc.perl.org/perlretut.html e para a página de referência, ver http://perldoc.perl.org/perlre.html

Exemplos

k=strindex('SCI/demos/scicos','/')
k=strindex('SCI/demos/scicos','SCI/')
k=strindex('SCI/demos/scicos','!')
k=strindex('aaaaa','aa')
k=strindex('SCI/demos/scicos',['SCI','sci'])
[k,w]=strindex('1+3*abc/2.33',['+','-','*','/'])
k=strindex('2' ,'/2(]*)?$\1/' ,'r')
Report an issue
<< strcspn Cadeias de Caracteres (Strings) string >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:52:32 CET 2020