By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

need help on char array

P: n/a
JC
hi

i want to check a char in the char array

public void characters(char[] chars, int start, int length)
{
if (chars!='/n' || chars((char)'/r'))
{
System.out.println("String read is " +
new String(chars, start, length));
}
}

thanks

JC
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"JC" <JC@JC.com> wrote in message news:40**********@rain.i-cable.com...
hi

i want to check a char in the char array

public void characters(char[] chars, int start, int length)
{
if (chars!='/n' || chars((char)'/r'))
{
System.out.println("String read is " +
new String(chars, start, length));
}
}


I hope you know that this line:

if (chars!='/n' || chars((char)'/r'))

should be something like [assuming you want to eliminate both newline and
carriage return]:

if (chars[i] != '\n' && chars[i] != '\r')

The expanded code, though I'm not certain what it is you are wanting to
accomplish:

for (int i = 0; i < chars.length; ++i)
{
...
if (chars[i] != '\n' && chars[i] != '\r')
{
...
}
}

I hope this helps.

Anthony Borla

Jul 17 '05 #2

P: n/a

"JC" <JC@JC.com> wrote in message news:40**********@rain.i-cable.com...
hi

i want to check a char in the char array

public void characters(char[] chars, int start, int length)
{
if (chars!='/n' || chars((char)'/r'))
{
System.out.println("String read is " +
new String(chars, start, length));
}
}


I hope you know that this line:

if (chars!='/n' || chars((char)'/r'))

should be something like [assuming you want to eliminate both newline and
carriage return]:

if (chars[i] != '\n' && chars[i] != '\r')

The expanded code, though I'm not certain what it is you are wanting to
accomplish:

for (int i = 0; i < chars.length; ++i)
{
...
if (chars[i] != '\n' && chars[i] != '\r')
{
...
}
}

I hope this helps.

Anthony Borla

Jul 17 '05 #3

P: n/a
JC
i use a for loop before. but no use for my coding. i need to read a XML file
and save all these data to a java array. i want to skip the return and new
line char. Can anyone give me some idea?

Thanks

JC

"Anthony Borla" <aj*****@bigpond.com> wrote in message
news:wc*****************@news-server.bigpond.net.au...

"JC" <JC@JC.com> wrote in message news:40**********@rain.i-cable.com...
hi

i want to check a char in the char array

public void characters(char[] chars, int start, int length)
{
if (chars!='/n' || chars((char)'/r'))
{
System.out.println("String read is " +
new String(chars, start, length));
}
}


I hope you know that this line:

if (chars!='/n' || chars((char)'/r'))

should be something like [assuming you want to eliminate both newline and
carriage return]:

if (chars[i] != '\n' && chars[i] != '\r')

The expanded code, though I'm not certain what it is you are wanting to
accomplish:

for (int i = 0; i < chars.length; ++i)
{
...
if (chars[i] != '\n' && chars[i] != '\r')
{
...
}
}

I hope this helps.

Anthony Borla

Jul 17 '05 #4

P: n/a
JC
i use a for loop before. but no use for my coding. i need to read a XML file
and save all these data to a java array. i want to skip the return and new
line char. Can anyone give me some idea?

Thanks

JC

"Anthony Borla" <aj*****@bigpond.com> wrote in message
news:wc*****************@news-server.bigpond.net.au...

"JC" <JC@JC.com> wrote in message news:40**********@rain.i-cable.com...
hi

i want to check a char in the char array

public void characters(char[] chars, int start, int length)
{
if (chars!='/n' || chars((char)'/r'))
{
System.out.println("String read is " +
new String(chars, start, length));
}
}


I hope you know that this line:

if (chars!='/n' || chars((char)'/r'))

should be something like [assuming you want to eliminate both newline and
carriage return]:

if (chars[i] != '\n' && chars[i] != '\r')

The expanded code, though I'm not certain what it is you are wanting to
accomplish:

for (int i = 0; i < chars.length; ++i)
{
...
if (chars[i] != '\n' && chars[i] != '\r')
{
...
}
}

I hope this helps.

Anthony Borla

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.