Replace a character in java?
<pre><code>public void sendData(){
         try {
            URL data = new URL("http://mywebsite.net/isvalid.php?username=" + usernameField.getText() + "&amp;password=" + passwordField.getText());
            BufferedReader in = new BufferedReader(
            new InputStreamReader(data.openStream()));

            String inputLine;
            while ((inputLine = in.readLine()) != null)
             if(inputLine.length() &gt; 0)
              inputString = inputLine;
                in.close();
            if(!inputString.equals("Incorrect password.")){
                System.out.println("Correct password");
                run();
                dispose();
            } else 
                if(usernameField.getText().length() &gt; 0 &amp;&amp; passwordField.getText().length() &gt; 0) {
                invalidUP();
                System.out.println("Invalid username or password.");
                }  else
                    if(usernameField.getText().length() &lt; 1 || (passwordField.getText().length() &lt; 1)) {
                        System.out.println("No password or username entered.");
                        upLength();
            }
         } catch (IOException e) {
       e.printStackTrace();
         }
     }
</code></pre>

<p>How would I check if usernameField or passwordField would have a space in it? And if it has, replace it with "_". </p>

<p>Also, if you think this method is wrong to send data or it can be done easier/quicker, please elaborate.</p>
