aspose file tools*
The moose likes Beginning Java and the fly likes Searching & Replacing Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Searching & Replacing Strings" Watch "Searching & Replacing Strings" New topic
Author

Searching & Replacing Strings

Vinod Kumar
Greenhorn

Joined: Jan 22, 2002
Posts: 10
Hello,
I am new to searching strings so can someone please explain how to do this? I have an XML file with characters such as [%, ^, &, $, #, !] that I want to replace with a space. How would I do that? When executing the application, the user will specify an argument like this:
java SearchMe Hello%Vacation!
And the program should replace the %, and ! with a space and output like this:
Hello Vacation
Also, is the XML approach good or bad?
Thanks,
Vinu.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
This is from the String class definition in The JavaTM 2 Platform, Standard Edition, v 1.3.1 - API Specification.

public String replace(char oldChar, char newChar)
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar.

Note: This method is available to String objects. So...
String newString = oldString.replace(oldChar, newChar);
Good Luck,
-Dirk Schreckmann
[ February 06, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Searching & Replacing Strings
 
Similar Threads
Immutable String ??
Assignment 1.1 spacing
String replace
Can you simulate String.replace(...) & String.contains(...)
new line character