• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help to write this logic

 
ali ddd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need the for loop. After you build str3 all you need is
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
ali ddd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
Actually this method is available only in JDK1.4,our application still uses the JDK 1.3
Cheers
 
Henry Wong
author
Marshal
Pie
Posts: 21515
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic