title: How to sum of two number of a String in Swift
body: <p>How can I add two number in a string, I do this here but it doesn't work, it says at the line </p>
  
  <p><code>var result = Int(char1) + Int(char2)</code></p>
  
  <p><strong>cannot invoke initializer for type 'int' with an agurment list of type '(Character)'</strong></p>
  
  <pre><code>import UIKit
  
  var str: String = "1 + 2"
  var char1 = str[str.startIndex.advancedBy(0)]
  var char2 = str[str.startIndex.advancedBy(4)]
  
  var result = Int(char1) + Int(char2)
  </code></pre>
  
  <p><strong>Edit1:</strong></p>
  
  <p>After do as @Phillip Mills said, it works, but I have one small question:</p>
  
  <pre><code>import UIKit
  
  var str: String = "1 + 2"
  var char1 = str[str.startIndex]
  var char2 = str[str.endIndex] //error: Execution was interrupted, reason: EXC_BADINSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
  
  var result = Int(String(char1))! + Int(String(char2))!
  </code></pre>
  
  <p>Why str.startIndex work, but str.endIndex not work?</p>
  
  <p><a href="https://www.freewebmentor.com/2018/02/swift-program-add-two-numbers.html" rel="nofollow noreferrer">https://www.freewebmentor.com/2018/02/swift-program-add-two-numbers.html</a></p>