title: Count and Substring the number
body: <p>Based on the format given e.g. <code>PPYYNNNN</code> and <code>Word = EXO</code>, 
  I need to get count of "P" in the format.
  Based on the number of "P" I need to get the word.</p>
  
  <p>e.g. number of "P" = 2, and word = EX</p>
  
  <p>If count of "P" equals to 2 then it gets 2 first letters from the word 
  and if count of "P" equals to 1 then it gets first letter from the word</p>
  
  <p>Tried using <code>substring</code> but could not work</p>
  
  <p>Any idea how to do it. </p>