Solved

line.startsWith

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

705 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

20 Experts available now in Live!

Get 1:1 Help Now