avatarjb stevenard

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1499

Abstract

ject and opposite way).</p> <figure id="36e3"> <div> <div>

            <iframe class="gist-iframe" src="/gist/jbstevenard/f4082d26502d79893e4962214d3967b7.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="ece5">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.</p>
    <figure id="23d3">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/jbstevenard/4a9ba0c202905e483950790b604ae942.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="4f72">You can split a string according to a substring.</p>
    <figure id="9c6f">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/jbstevenard/05ea40beff9876f772f2fb076f14463c.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="ac00">You can also get the Unicode value of each character for the string using their utf8/utf16 

Options

properties. To get a character from an Int, use the UnicodeScalar class.</p> <figure id="e463"> <div> <div>

            <iframe class="gist-iframe" src="/gist/jbstevenard/cb976898a31f8be2b7c0fc59519f4ee5.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="a50f"><b>Strings are famous in interview questions</b>; as input or output, we should not ignore them and get used to them.</p><p id="9d91"><a href="https://readmedium.com/dictionary-b8af7597aa5a">&lt;&lt; Dictionaries</a> | <a href="https://readmedium.com/learn-data-structures-and-algorithms-with-swift-5-6-d9f36a4027dd">Book</a> | <a href="https://readmedium.com/sets-b6b7a5dd04f7">Sets &gt;&gt;</a></p><div id="8acf" class="link-block">
      <a href="https://medium.com/@jbstevenard/membership">
        <div>
          <div>
            <h2>Join Medium with my referral link - jb stevenard</h2>
            <div><h3>Read every story from jb stevenard (and thousands of other writers on Medium). Your membership fee directly supports jb…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*LLOFX6T9gg6rcgut)"></div>
          </div>
        </div>
      </a>
    </div></article></body>

Strings

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

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.

<< Dictionaries | Book | Sets >>

Data Structures
Algorithms
Coding
Programming
String
Recommended from ReadMedium