title: Switch placement of values in comma delimited string
body: <p>I have a comma delimited string held within a database field that could contain any number of values:</p>
  
  <pre><code>23,45,21,40,67,22
  </code></pre>
  
  <p>I need to be able to somehow switch two values, so for example I know I need to move 45 one position down the string, so I end up with:</p>
  
  <pre><code>23,21,45,40,67,22
  </code></pre>
  
  <p>The reason for this is that the numbers all correspond to the IDs held in another database table, and their position in the sting determine the order those items will be printed on screen. Before you ask about database design - I've inherited it and it cannot be changed without significant work to an entire application.</p>
  
  <p>So I've thought about exploding the string, identifying the position of the target number and swapping it with the one next-door, but I'm unsure of how this can be achieved when the total number of values is not known.</p>
  
  <p>Any things? I suspect the solution will be cumbersome, but needs must!!</p>