title: Looking to parse EMV data into TLV
body: <p>Okay - I have this hex data and I have a list of tags:</p>
  
  <p>the raw data may look like this:</p>
  
  <pre><code>5F201A54444320424C41434B20554E4C494D49544544205649534120204F07A00000000310105F24
  </code></pre>
  
  <p>Because I have a list of tags I can see there are multiple values here
  Tags [5f20, 4f, 5f24]</p>
  
  <blockquote>
    <p>Ex:
    <strong>5F20</strong>1A54444320424C41434B20554E4C494D4954454420564953412020<strong>4F</strong>07A0000000031010<strong>5F24</strong>…ETC</p>
  </blockquote>
  
  <p>So - I know that I have this tag [5f20] and its value is all the other stuff in between [5f20] and [4f]. — </p>
  
  <p>I can take this other stuff: </p>
  
  <blockquote>
    <p>1A54444320424C41434B20554E4C494D4954454420564953412020 and create a string from it which becomes:
    ("TDC BLACK UNLIMITED VISA“)</p>
  </blockquote>
  
  <p>I can parse through a small section of it like using:</p>
  
  <pre><code>    let string2 = 
      "5F201A54444320424C41434B20554E4C494D49544544205649534120204F"
      var string3: String = ""
      if let startRange2 = string2.range(of: "5F20"),
      let endRange2 = string2.range(of: "4F")
      {
      let contents2 = String(string2[startRange2.upperBound..
      &lt;endRange2.lowerBound])
      print(string3)
      string3 = contents2
      }
  </code></pre>
  
  <p>What Im not sure about is:
  How do I scale this up to work with data where I wont know what tag will be first or second or how many there are? Im seriously stumped and I don't know where to go from here.</p>
  
  <p>Overall my goal is to get create readable data like this:
  <a href="https://i.stack.imgur.com/huxs4.png" rel="nofollow noreferrer">Clean formatted Tags and value</a></p>
  
  <p>look something like this:</p>
  
  <blockquote>
    <p>5F201A54444320424C41434B20554E4C494D49544544205649534120204F07A00000000310105F24032307319F160F4243544553542031323334353637389F21031826509A031406179F02060000000000019F03060000000000009F34030203009F120C56495341204352454449544F9F0607A00000000310105F300202019F4E0F616263640000000000000000000000C408491573FFFFFF1097C00A09117101800165E0000AC2820168D9DE289AAD770BE408F6B1D4E0A2576CEA7F03CD479CE3A1827375D6C4D4959ACDB5D3B6F84CD83430F4346C35E48A77A0D5F36FBEA444C2D8701C07FFC7AF06C0485D68F7A83FC30840D3C0766EC4EE669BE5A42BAD4C7459680FAAAE9C4EFEFFEB5A590E53B3E91B3CD28A415C2C9484E26DA5A15592BBCD1F45CF49D27A9D480B031957DF8C790C55FF60DB192CCD070FA4F7BCDC99E7F7567C2F991B5536F9336BA66D68115D54BC3642A9CA47FDD162FCDC33E455AAC283975DACC98CBE9A6611E996F0740072CF8E32D3D9F39F4BB25568F5CC3E7F5DE158E4D62BF4E7185CF13BD068C4F062C26A3BBF88E056F249130E89AA29E52A1EBB6BAD98296822F10949F0C825D1449DA7EF4431AB846D0DDB916F2901359DD9A3B3395BAC9F9BE4D24657F65B030DDADA53577A14D9F5F776B6FF7EAB99D8C4BB08BEF2016C72D94B1DB91BCF0238405B7857646DCE5F79871D96B6A6652090FD8CFCC59973433919A6D0533DFE</p>
  </blockquote>