     "metadata": {},
     "source": [
      "## Algorithm\n",
      "\n",
      "![alt text](https://raw.githubusercontent.com/donnemartin/algorithms-data-structures/master/images/replace_string.jpg)\n",
      "\n",
      "Since Python strings are immutable, we'll use a bytearray instead to exercise in-place string manipulation as you would get with a C string (which is null terminated, as seen in the above diagram).  For the python bytearray we will not use a null terminator.\n",
      "\n",
      "* Count the number of spaces in the bytearray\n",
      "* Determine the new bytearray length\n",
 
</s> remove     "Since Python strings are immutable, we'll use a bytearray instead to exercise in-place string manipulation as you would get with a C string (which is null terminated, as seen in the above diagram).  For the python bytearray we will not use a null terminator.\n",
 </s> add     "![alt text](https://raw.githubusercontent.com/donnemartin/algorithms-data-structures/master/images/replace_string.jpg)\n", </s> remove     "* NULL\n",
 </s> add     "* NULL->NULL\n", </s> remove     "    return string.replace(' ', '%20')"
 </s> add     "    return string.replace(' ', '%20')\n",
    "\n",
    "run_tests(encode_spaces_alt)\n",
    "run_tests(encode_spaces_alt2)" </s> remove     "str0 = None\n",
    "str1 = bytearray(' ||')\n",
    "str2 = bytearray(' foo bar ||||||')\n",
    "str3 = bytearray('foo')\n",
    "encode_spaces(str0, 0)\n",
    "encode_spaces(str1, 1)\n",
    "encode_spaces(str2, 9)\n",
    "encode_spaces(str3, 3)\n",
    "print(str0)\n",
    "print(str1)\n",
    "print(str2)\n",
    "print(str3)"
 </s> add     "run_tests(encode_spaces)"
    "Since Python strings are immutable, we'll use a bytearray instead to exercise in-place string manipulation as you would get with a C string (which is null terminated, as seen in the diagram below).  For the python bytearray we will not use a null terminator.\n",
     "metadata": {},
     "source": [
      "## Algorithm\n",
      "\n",
    "Since Python strings are immutable, we'll use a bytearray instead to exercise in-place string manipulation as you would get with a C string (which is null terminated, as seen in the diagram below).  For the python bytearray we will not use a null terminator.\n",
      "\n",
      "Since Python strings are immutable, we'll use a bytearray instead to exercise in-place string manipulation as you would get with a C string (which is null terminated, as seen in the above diagram).  For the python bytearray we will not use a null terminator.\n",
      "\n",
      "* Count the number of spaces in the bytearray\n",
      "* Determine the new bytearray length\n",
keep keep keep keep replace keep keep keep keep keep
 Updated unit test to use nose and moved it to Test Cases section.  Tweaked algorithm description. 
arrays-strings/replace_char.ipynb