?
Solved

line.startsWith

Posted on 2008-10-27
5
Medium Priority
?
890 Views
Last Modified: 2012-06-21
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
Comment
Question by:chima
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22818206
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
 

Author Comment

by:chima
ID: 22818737
mwvisa1, I considered that, and none work.  Any other thoughts?
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22818789
Please show me your String as that worked for me.
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22818800
While you are getting your String, see if it has spaces in front.

Try:
if (line.trim().startsWith("?xml", 1))
0
 

Author Closing Comment

by:chima
ID: 31510592
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question