Strings

This is not really a data structure compared to arrays and dictionaries but still strings are sequences of characters.

jb stevenard
1 min readAug 14, 2022

Because a string is a sequence of characters, you can apply all sequences (like arrays) functions, loop, substrings, insert string, first/last occurrences, concatenation, comparison, …

But also, other concepts palindrome (can be read both ways: anna, bob, …), anagram (same characters but different orders: actors, castor, …), serialization (create a string from an object and opposite way).

Because strings can contain characters of different sizes (English alphabet, Chinese characters or Emojis uses different memory sizes), we cannot directly access each character. Still, there is a simple way to do it using the following extension.

You can split a string according to a substring.

You can also get the Unicode value of each character for the string using their utf8/utf16 properties. To get a character from an Int, use the UnicodeScalar class.

Strings are famous in interview questions; as input or output, we should not ignore them and get used to them.

--

--

jb stevenard

iOS Software Engineer @Meta, ex: TikTok, Agoda. Nature Lover, Tech & Personal Finance, Food & Training Addict. https://medium.com/@jbstevenard/membership