Hi,

I've been working on this program for a while now. It's called webmaster and basically you reading in a webpage and formatting it however you want. However there are two parts are difficult. They work but not how i want them to.

The first part is reversing the html code of the webpage. I have the reversion but it only shows up in netbeans and not on the webpage as how it's supposed to.

The second part is searching for a word the user enters and counting and displaying the amount of times it appears on the webpage. It works for some words but not others

If anybody can help me if would wonderful.

Code:
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Scanner;

public class WebProcessor {

    public static String getWebContents(String url) {
        BufferedReader br = null;
        String result = null;
        try {
            URL toFetch = new URL(url);
            br = new BufferedReader(new InputStreamReader(toFetch.openStream()));
            StringBuilder ret = new StringBuilder();
            String line = br.readLine();
            while (line != null) {
                ret.append(line);
                line = br.readLine();
            }
            result = ret.toString();
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
            System.err.println("Malformed url:  " + url);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            System.err.println("Error reading from url:  " + url);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                    System.err.println("Couldn't close connection to url properly:  " + url);
                }
            }
            return result;
        }
    }

    public static void saveDoc(String contents, String filename) {
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(new FileWriter(new File(filename)));
            pw.print(contents);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            System.err.println("Error writing to file:  " + filename);
        } finally {
            if (pw != null) {
                pw.close();
            }
        }
    }

    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Please enter a valid URL (be sure to include \"http://\" at the beginning).");
        String URL = keyboard.nextLine();
        String contents = getWebContents(URL);
        String saveFile = "C:\\URL.html";
        saveDoc(contents, saveFile);

        System.out.println("Please enter a string.\nThe number of appearances of this string in the contents of the URL you entered will be counted and displayed.");
        String countedStr = keyboard.nextLine();
        int strCount = 0;
        for (int i = 0; i < (contents.length() - countedStr.length()); i++) {
            String contentsCheck = contents.substring(i, i + countedStr.length());
            if ((contentsCheck.equals(countedStr)) || (contentsCheck.equals(countedStr.toLowerCase())) || (contentsCheck.equals(countedStr.toUpperCase().charAt(0) + countedStr.toLowerCase().substring(1, countedStr.length())))) {
                strCount++;
            }
        }
        if (strCount == 1) {
            System.out.println("The string you entered was found in the contents of the URL " + strCount + " time.");
        } else {
            System.out.println("The string you entered was found in the contents of the URL " + strCount + " times.");
        }

        System.out.println("Please enter another string.\nAll occurences of that string in the contents of the entered URL will be given bold characters.");
        String str = keyboard.nextLine();
        String contentsEdit = "";
        boolean strContained = false;
        for (int i = 0; i < (contents.length() - str.length()); i++) {
            String contentsCheck = contents.substring(i, i + str.length());
            if ((contentsCheck.equals(str)) || (contentsCheck.equals(str.toLowerCase())) || (contentsCheck.equals(str.toUpperCase().charAt(0) + str.toLowerCase().substring(1, str.length())))) {
                strContained = true;
                contentsEdit = contents.substring(0, i) + "<b>" + contentsCheck + "</b>" + contents.substring(i + str.length(), contents.length());
                i = i + 3;
            } else {
                strContained = false;
            }
            if (strContained == true) {
                contents = contentsEdit;
            }
        }
        
        System.out.println("Please enter another string.\nAll occurences of that string in the contents of the entered URL will be italicized.");
        str = keyboard.nextLine();
        contentsEdit = "";
        strContained = false;
        for (int i = 0; i < (contents.length() - str.length()); i++) {
            String contentsCheck = contents.substring(i, i + str.length());
            if ((contentsCheck.equals(str)) || (contentsCheck.equals(str.toLowerCase())) || (contentsCheck.equals(str.toUpperCase().charAt(0) + str.toLowerCase().substring(1, str.length())))) {
                strContained = true;
                contentsEdit = contents.substring(0, i) + "<i>" + contentsCheck + "</i>" + contents.substring(i + str.length(), contents.length());
                i = i + 3;
            } else {
                strContained = false;
            }
            if (strContained == true) {
                contents = contentsEdit;
            }
        }
        
        System.out.println("Please enter another string.\nAll occurences of that string in the contents of the entered URL will be underlined.");
        str = keyboard.nextLine();
        contentsEdit = "";
        strContained = false;
        for (int i = 0; i < (contents.length() - str.length()); i++) {
            String contentsCheck = contents.substring(i, i + str.length());
            if ((contentsCheck.equals(str)) || (contentsCheck.equals(str.toLowerCase())) || (contentsCheck.equals(str.toUpperCase().charAt(0) + str.toLowerCase().substring(1, str.length())))) {
                strContained = true;
                contentsEdit = contents.substring(0, i) + "<u>" + contentsCheck + "</u>" + contents.substring(i + str.length(), contents.length());
                i = i + 3;
            } else {
                strContained = false;
            }
            if (strContained == true) {
                contents = contentsEdit;
            }
        }
        
        System.out.println("Next, you will need to input two integers, corresponding to a start position and end position, respectively.\nThe characters within this range in the contents of the entered URL will be reversed.\nPlease enter the start position.");
        String startPos = keyboard.nextLine();
        int startPosInt = Integer.parseInt(startPos);
        System.out.println("Please enter an end position.");
        String endPos = keyboard.nextLine();
        int endPosInt = Integer.parseInt(endPos);
        str = contents.substring(startPosInt, endPosInt);
        String reverseStr = "";
        for (int i = str.length()-1; i >= 0; i--){
            reverseStr = reverseStr + str.charAt(i);
        }
        contentsEdit = contents.substring(0,startPosInt) + reverseStr + contents.substring(endPosInt, contents.length());
        contents = contentsEdit;
        
        System.out.println("Please enter another string.\nAll occurences of that string in the contents of the URL entered will be deleted.");
        str = keyboard.nextLine();
        contentsEdit = "";
        strContained = false;
        for (int i = 0; i < (contents.length() - str.length()); i++) {
            String contentsCheck = contents.substring(i, i + str.length());
            if ((contentsCheck.equals(str)) || (contentsCheck.equals(str.toLowerCase())) || (contentsCheck.equals(str.toUpperCase().charAt(0) + str.toLowerCase().substring(1, str.length())))) {
                strContained = true;
                contentsEdit = contents.substring(0, i) + contents.substring(i + str.length(), contents.length());
                i = i + 3;
            } else {
                strContained = false;
            }
            if (strContained == true) {
                contents = contentsEdit;
            }
        }
        
        System.out.println("Please enter another string.\nAll occurences of that string in the contents of the entered URL will be centered.");
        str = keyboard.nextLine();
        contentsEdit = "";
        strContained = false;
        for (int i = 0; i < (contents.length() - str.length()); i++) {
            String contentsCheck = contents.substring(i, i + str.length());
            if ((contentsCheck.equals(str)) || (contentsCheck.equals(str.toLowerCase())) || (contentsCheck.equals(str.toUpperCase().charAt(0) + str.toLowerCase().substring(1, str.length())))) {
                strContained = true;
                contentsEdit = contents.substring(0, i) + "<center>" + contentsCheck + "</center>" + contents.substring(i + str.length(), contents.length());
                i = i + 8;
            } else {
                strContained = false;
            }
            if (strContained == true) {
                contents = contentsEdit;
            }
        }
        
        saveDoc(contents, saveFile);
    }
}
Thanks