Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.3.3 - English

Change language to:
Français - 日本語 - Português

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

Scilab help >> Strings > strindex

strindex

search position of a character string in an other string.

Calling Sequence

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

Arguments

haystack

A character string. The string where to search occurrences of needle

needle

A character string or character string vector . The string(s) to search in haystack

ind

vector of indexes

which

vector of indexes

flag

string("r" for regular expression)

Description

strindex searches indexes where needle (i) is found in haystack

for each k it exist a i shuch that part(haystack,ind(k)+(0:length(needle(i))-1)) is the same string than needle(i). If which argument is required it contains these i. When using the third parameters "r", the needle should be a string of regular expression. And then strindex is going to match it with haystack according to the regular express rules.

strindex without regular expression argument is based on Knuth-Morris-Pratt algoritm.

This algorithm is more powerful than that used in scilab 4.x. In some special case, result can be different.

example:

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

The rules of regular expression are similar to perl language. For a quick start , see http://perldoc.perl.org/perlrequick.html. For a more in-depth tutorial on , see http://perldoc.perl.org/perlretut.html and for the reference page, see http://perldoc.perl.org/perlre.html

Examples

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

See Also

  • string — conversion to string
  • strings — Scilab Object, character strings
  • regexp — find a substring that matches the regular expression string
  • strsubst — substitute a character string by another in a character string.
<< strcspn Strings string >>

Copyright (c) 2022-2024 (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:
Wed Oct 05 12:10:01 CEST 2011