summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/string
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2018-06-22 11:00:22 +0200
committerGitHub <noreply@github.com>2018-06-22 11:00:22 +0200
commit87813c9f3aa0a6d0777f554bb5aaa10452c6ec92 (patch)
treeb4123184f18d7c4dfcb110e28258d428bf0ff377 /docs/examples/tutorial/string
parent216f998e31667b6945f775dbc7e3e01759029bd6 (diff)
parent3f5848fcaa7a2a495d83d2003ba02a8295f51b3f (diff)
downloadcython-87813c9f3aa0a6d0777f554bb5aaa10452c6ec92.tar.gz
Merge pull request #2389 from gabrieldemarmiesse/test_string_14
Adding tests for "Unicode and passing strings" part 14
Diffstat (limited to 'docs/examples/tutorial/string')
-rw-r--r--docs/examples/tutorial/string/for_bytes.pyx6
-rw-r--r--docs/examples/tutorial/string/for_unicode.pyx6
-rw-r--r--docs/examples/tutorial/string/if_char_in.pyx5
3 files changed, 17 insertions, 0 deletions
diff --git a/docs/examples/tutorial/string/for_bytes.pyx b/docs/examples/tutorial/string/for_bytes.pyx
new file mode 100644
index 000000000..1740ae236
--- /dev/null
+++ b/docs/examples/tutorial/string/for_bytes.pyx
@@ -0,0 +1,6 @@
+cdef bytes bytes_string = b'hello world'
+
+cdef char c
+for c in bytes_string:
+ if c == 'A':
+ print("Found the letter A")
diff --git a/docs/examples/tutorial/string/for_unicode.pyx b/docs/examples/tutorial/string/for_unicode.pyx
new file mode 100644
index 000000000..aabd562e4
--- /dev/null
+++ b/docs/examples/tutorial/string/for_unicode.pyx
@@ -0,0 +1,6 @@
+cdef unicode ustring = u'Hello world'
+
+# NOTE: no typing required for 'uchar' !
+for uchar in ustring:
+ if uchar == u'A':
+ print("Found the letter A")
diff --git a/docs/examples/tutorial/string/if_char_in.pyx b/docs/examples/tutorial/string/if_char_in.pyx
new file mode 100644
index 000000000..aa684bcee
--- /dev/null
+++ b/docs/examples/tutorial/string/if_char_in.pyx
@@ -0,0 +1,5 @@
+cpdef void is_in(Py_UCS4 uchar_val):
+ if uchar_val in u'abcABCxY':
+ print("The character is in the string.")
+ else:
+ print("The character isn't in the string")