title: Objective C if and appending NSMutableString statements/modification
body: <p>I have a complex question which may be very simple for you guyz.</p>
  
  <p>I have a </p>
  
  <blockquote>
    <p><code>NSMutableString = "This is spinach";</code></p>
  </blockquote>
  
  <p>I have 3 Booleans. Please ignore the code. I havent used proper syntax,functions. </p>
  
  <pre><code>if (boolA) appendstring"and apples";
  
   if (boolB) appendstring"and mangoes";
  
   if (boolC) appendstring"and oranges";
  </code></pre>
  
  <p>every boolean corresponds to a fruit.
  Say if BOOL a is true, I also have mangoes!</p>
  
  <p>Anyway, my goal is to format the initial String by appending the other fruits if the corresponding booleans are true and present in a very specific way.</p>
  
  <p>Heres the scenario if BOOL A is true, the string should be "This is spinach and mangoes"
  Note the added "and" with mangoes. I can add it straight away with apending at the end.</p>
  
  <p>But the problem is when all the BOOLeans are true.
  The string will look like "This is spinach and apples and mangoes and oranges" and this i can achieve.</p>
  
  <p>I want to make it look like "This is spinach And apples, mangoes, oranges"
  Notice that I want to add "And" only once immediately after and notice the commas "," before mangoes and oranges.</p>
  
  <p>I can get this probably, but with alot of checks and ALOt of unnecessary if/else statements.</p>
  
  <p>I was thinking that I could jus turn</p>
  
  <pre><code>"This is spinach and apples and mangoes and oranges" into 
  "This is spinach and apples , mangoes , oranges".
  </code></pre>
  
  <p>im guessing there is some kind of function i can use to do this. Like replacing the second and the third "<strong>and</strong>" with "<strong>,</strong>".  </p>
  
  <p>Could you guys please lemme know of a function like this and an example to do it. This was possible i think in CPP back in the day.. using strpos() to get location of a char and then do something after a certain number and replace string. Or let me know if theres a better way.</p>