Domanda

Supponendo che si dispone di una stringa:

str = “ab,cd,ef” 

e voglio suddividere in un elenco

lst = [“ab”,”cd”,ef”]

Come posso fare meglio, supponendo che non posso sapere in anticipo come il numero di elementi presenti nella stringa?


Fondamentalmente sto cercando un specman equivalente a Perl:

$str = "ab,cd,ef";
@lst = split /,/, $str;
È stato utile?

Soluzione

str_split è ciò che si desidera.

Da Specman 6.1 documenti:

str_split(str: string, regular-exp: string): list of string

Esempio Di Sintassi

var s: list of string = str_split("first-second-third", "-"); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top