Julia – 18 – stringhe – 4

Continuo da qui, copio qui.

Operazioni comuni
You can lexicographically compare strings using the standard comparison operators:

You can search for the index of a particular character using the search() function:

You can start the search for a character at a given offset by providing a third argument:

You can use the contains() function to check if a substring is contained in a string:

The last error is because 'o' is a character literal, and contains() is a generic function that looks for subsequences. To look for an element in a sequence, you must use in() instead.

Two other handy string functions are repeat() and join():

Nota per me: join() ha una sintassi particolare, da ricordarselo.

Some other useful functions include:

  • endof(str) gives the maximal (byte) index that can be used to index into str.
  • length(str) the number of characters in str.
  • i = start(str) gives the first valid index at which a character can be found in str (typically 1).
  • c, j = next(str,i) returns next character at or after the index i and the next valid character index following that. With start() and endof(), can be used to iterate through the characters in str.
  • ind2chr(str,i) gives the number of characters in str up to and including any at index i.
  • chr2ind(str,j) gives the index at which the jth character in str occurs.

Stringhe letterali non standard
There are situations when you want to construct a string or use string semantics, but the behavior of the standard string construct is not quite what is needed. For these kinds of situations, Julia provides non-standard string literals. A non-standard string literal looks like a regular double-quoted string literal, but is immediately prefixed by an identifier, and doesn’t behave quite like a normal string literal. Regular expressions, byte array literals and version number literals, as described below, are some examples of non-standard string literals. Other examples are given in the Metaprogramming [prossimamente] section.


Posta un commento o usa questo indirizzo per il trackback.



Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: