Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Français


strspn

lengths of the beginning of strings as long as characters are among those allowed

Syntax

headsLengths = strspn(Strings, allowedChars)

Arguments

Strings, allowedChars

Matrices of strings, of identical dimensions. allowedChars can be a scalar string. It is then used for all Strings components.

headsLengths

Matrix of positive real integers, of the size of Strings: lengths of the selected Strings heads.

Description

headsLengths = strspn(Strings, allowedChars) returns the length of the initial portion of Strings which consists only of characters that are part of allowedChars.

Examples

allowed = "0":"9"
strspn("129th or the 130th", allowed)

t = ["characters" "matrix" ; "text" "strings"]
allowed = "a":"s"
strspn(t, allowed)

allowed = ["a":"j", "a":"u" ; "d":"u", "g":"v"]
strspn(t, allowed)
--> allowed = "0":"9"
 allowed  =
  "0123456789"

--> strspn("129th or the 130th", allowed)
 ans  =
   3.


--> t = ["characters" "matrix" ; "text" "strings"]
 t  =
  "characters"  "matrix"
  "text"        "strings"

--> allowed = "a":"s"
 allowed  =
  "abcdefghijklmnopqrs"
--> strspn(t, allowed)
 ans  =
   6.   2.
   0.   1.

--> allowed = ["a":"j", "a":"u" ; "d":"u", "g":"v"]
 allowed  =
  "abcdefghij"          "abcdefghijklmnopqrstu"
  "defghijklmnopqrstu"  "ghijklmnopqrstuv"

--> strspn(t, allowed)
 ans  =
   3.   5.
   2.   7.

With UTF-8 extended characters:

t = "Να αμφιβάλλετε τα πάντα ή να μην αμφιβάλλετε τίποτα: " + ..
    "δύο ίσοι τρόποι αποφυγής σκέψης.";
t = matrix(strsplit(t," "), 2,-1)
allowed = "Ναβγδεϵζηθικλμνξοπρστυφϕχψωϐϑϰϱςϖ";
strspn(t, allowed)
--> t = matrix(strsplit(t," "), 2,-1)
 t  =
  "Να"           "τα"     "ή"   "μην"          "τίποτα:"  "ίσοι"    "αποφυγής"
  "αμφιβάλλετε"  "πάντα"  "να"  "αμφιβάλλετε"  "δύο"      "τρόποι"  "σκέψης."

--> allowed = "Ναβγδεϵζηθικλμνξοπρστυφϕχψωϐϑϰϱςϖ";
--> strspn(t, allowed)
 ans  =
   2.   2.   0.   3.   1.   0.   6.
   5.   1.   2.   5.   1.   2.   2.

See also

  • strcspn — lengths from the beginning of strings until a character among those prohibited
  • strncpy — copy the N first characters of the given strings
  • part — Extraction of characters from strings
Report an issue
<< strsplit Chaînes de caractères strstr >>

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:
Mon Jun 17 17:52:28 CEST 2024