• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 910
  • Last Modified:

line.startsWith

Hello,
I am using if (line.startsWith("?xml", 2)) {  and it is not finding ?xml within the String.
Any suggestions as to why it is not finding the substring?
0
chima
Asked:
chima
  • 3
  • 2
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
Java is zero-based, so if you have an XML string that is like this

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>Hello World!</root>

Then the ?xml starts at index 1 NOT 2.

Try this:
if (xml.startsWith("?xml", 1))
0
 
chimaAuthor Commented:
mwvisa1, I considered that, and none work.  Any other thoughts?
0
 
Kevin CrossChief Technology OfficerCommented:
Please show me your String as that worked for me.
0
 
Kevin CrossChief Technology OfficerCommented:
While you are getting your String, see if it has spaces in front.

Try:
if (line.trim().startsWith("?xml", 1))
0
 
chimaAuthor Commented:
I do not have the problem now.  I think the .trim() was what was missing.
I got a question about an extra space that I am getting.  If you have the time to add your comments, I would appreciate it.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now