void setup(){ size(400, 400); // load the xml file as a string String lines[] = loadStrings("http://www.nytimes.com/services/xml/rss/nyt/Weddings.xml"); // join into one string String fileContents = join(lines, ""); // create a new string using find and replace String newFileContents = findAndReplace(fileContents, "’", "\'"); // print to window println(newFileContents); // save as file saveFile(newFileContents, "data/newFile.txt"); } String findAndReplace(String oldString, String toReplace, String replaceWith){ int currentIndex = 0; int previousIndex = 0; boolean firstReplace = true; String newString = ""; //string to hold data from our request while(currentIndex != -1){ // find the location of the string to replace currentIndex = oldString.indexOf(toReplace, previousIndex+1); //if not found if(currentIndex == -1){ if(firstReplace){ newString += oldString.substring(0, oldString.length()); firstReplace = false; } else { // add from the previous index to the end newString += oldString.substring(previousIndex+toReplace.length(), oldString.length()); } } else { // if found if(firstReplace){ // start from beginning of string newString += oldString.substring(0, currentIndex); newString += replaceWith; firstReplace = false; } else { // add from the previous to the location of the replace string newString += oldString.substring(previousIndex+toReplace.length(), currentIndex); newString += replaceWith; } } previousIndex = currentIndex; } return newString; } void saveFile(String contents, String url){ PrintWriter output; output = createWriter(url); output.println(contents); output.flush(); // Write the remaining data output.close(); // Finish the file }