Solved

line.startsWith

Posted on 2008-10-27
5
881 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

688 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