aspose file tools*
The moose likes Beginning Java and the fly likes Help to write this logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help to write this logic" Watch "Help to write this logic" New topic
Author

Help to write this logic

ali ddd
Greenhorn

Joined: Apr 27, 2006
Posts: 3
Hi need to write a logic which will remove <?xml version=1.0 encoding= UTF-8?> from the above string how will i do it please.
Thanks

public class HelloWorld {

// Display "Hello World!"
public static void main(String args[]) {
System.out.println("Hello World!");

String str = "<?xml version=1.0 encoding= UTF-8?> \n";
String str2 = str+"<table border=1 width=100> \n";
String str3 = str2+"<TH>Name</TH> \n"+
"<TH>Last Name</TH> \n"+
"<TH>state</TH> \n"+
"<TH>Country</TH> \n"+
"<TH>Currency</TH> \n";
System.out.println(str3.length());

String xmlProLogBegin = "<?xml";
String xmlProLogEnd = "?>";

for(int i=0; i<str3.length(); i++) {

}

}
}
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
You don't need the for loop. After you build str3 all you need is
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"ali ddd,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
ali ddd
Greenhorn

Joined: Apr 27, 2006
Posts: 3
Thanks,
Actually this method is available only in JDK1.4,our application still uses the JDK 1.3
Cheers
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18853
    
  40

Originally posted by ali ddd:
Thanks,
Actually this method is available only in JDK1.4,our application still uses the JDK 1.3
Cheers


It is actually not bad with JDK 1.3 -- instead of a one line regular expression, it could probably be done with 3 or 4 lines. (it look me only a few minutes to write the code)

With the way that you had the problem setup, the indexes can be calculated with a combinations of the indexOf() and length() methods. And the new string can be build by using the substring() methods to get the strings before and after the pattern.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help to write this logic