manipulating_strings/quickref.tex
changeset 523 54bdda4aefa5
parent 522 d33698326409
equal deleted inserted replaced
522:d33698326409 523:54bdda4aefa5
     2 
     2 
     3 String indexing starts from 0, like lists.
     3 String indexing starts from 0, like lists.
     4 
     4 
     5 \lstinline|s = `Hello World'|\\
     5 \lstinline|s = `Hello World'|\\
     6 \lstinline|s[0:5]| gives \texttt{Hello}\\
     6 \lstinline|s[0:5]| gives \texttt{Hello}\\
     7 \lstinline|s[6:]| gives \textt{World}\\
     7 \lstinline|s[6:]| gives \texttt{World}\\
     8 \lstinline|s[6::2]| gives \textt{Wrd}\\
     8 \lstinline|s[6::2]| gives \texttt{Wrd}\\
     9 
     9 
    10 \lstinline|s.replace('e', 'a')| returns a new string with all e's
    10 \lstinline|s.replace('e', 'a')| returns a new string with all e's
    11 replaced by a.  
    11 replaced by a.  
    12 
    12 
    13 \lstinline|s.lower()| and \lstinline|s.upper()| return new strings
    13 \lstinline|s.lower()| and \lstinline|s.upper()| return new strings