Solved

line.startsWith

Posted on 2008-10-27
5
868 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
  • 3
  • 2
5 Comments
 
LVL 59

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 59

Expert Comment

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
github account with ecipse 1 47
diffSum example 4 36
xampp tool 12 47
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

813 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now