Link to home
Start Free TrialLog in
Avatar of dalecon
dalecon

asked on

substring query



hi all

i have a string "<?xml version="1.0" encoding="UTF-8"?><node><element>some data</element></node>"

can someone tell me how i get the section <?xml version="1.0" encoding="UTF-8"?> and remove it from the string, so i am left with <node><element>some data</element></node>

many thanks

Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

s = "<?xml version="1.0" encoding="UTF-8"?><node><element>some data</element></node>";
s = s.substring(0, s.indexOf("<?")) + s.substring(s.stringOf(">?")+2, s.length());

or something similar using regex or even some other technique
Sorry, I made some typos. It should be:

    String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><node><element>some data</element></node>";
    s = s.substring(0, s.indexOf("<?")) + s.substring(s.indexOf("?>")+2, s.length());
    System.out.println(s);
ASKER CERTIFIED SOLUTION
Avatar of Nguyen Huu Phuoc
Nguyen Huu Phuoc
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dalecon
dalecon

ASKER



i get the string using jdom
Yeah you can use same as my post to remove the header. So, you needn't remove it.
Avatar of dalecon

ASKER



what jar is import org.dom4j.*; in, i can't find it


thanks
I use dom4j but jdom
Avatar of dalecon

ASKER

no worries found it
Avatar of dalecon

ASKER



cool that works