manipulating-strings/quickref.tex
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 09 Nov 2010 16:16:55 +0530
changeset 424 19f49715e83f
parent 285 7c4855fb8e5f
permissions -rw-r--r--
Changes to progress.org.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
285
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     1
\textbf{Manipulating strings}
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     2
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     3
String indexing starts from 0, like lists.
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
285
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     5
\lstinline|s = `Hello World'|\\
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     6
\lstinline|s[0:5]| gives \texttt{Hello}\\
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     7
\lstinline|s[6:]| gives \textt{World}\\
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     8
\lstinline|s[6::2]| gives \textt{Wrd}\\
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
285
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    10
\lstinline|s.replace('e', 'a')| returns a new string with all e's
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    11
replaced by a.  
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    12
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    13
\lstinline|s.lower()| and \lstinline|s.upper()| return new strings
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    14
with all lower and upper case letters, respectively.