The replace( ) method replaces all occurrences of one character in the invoking string with character. It has the following general form: String replace(char original, char replacements Here, original specifies the character to be replaced by the character specified by replacement. The resulting string is returned. For example,
The trim() method returns a copy of the invoking string from which any leading and trailing white space has been removed. It has this general form: , This puts the string “Hello World” into The trim( ) method is quite useful when you process user commands. For example, the following program prompts the user for the name of a state and then displays that state’s capital. It uses trim() to remove any leading or trailing white space that may have inadvertently been entered by $e user.