Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a character in a string 1

Status
Not open for further replies.

abyinsydney

Programmer
Feb 17, 2004
99
AU
greetings fellow citizen

Does any one has an idea about the following

i have a string like 000000-314.14

i need to read the string in java as soon as i encounter a non zero value it should return me the position of the counter.for instance while reading the string as soon as the cursor encounters - it should tell me the postion off -
idea being a non zero value cause another string can have the value to be 00000123.314.
Means as soon as i encounter a non zero value should let me know the position of the cursor

1. String z2 !="0";
2. int ya=g.lastIndexOf(z2);
3. System.out.println("value for ya is " +ya);

I'm getting an error on line 1.How do i initialise the value of z2 to be not equal to O
Can any one suggest me a problem to the same

Or if any one has some other solution

regards
aby
 
String s = "000000-314.14";
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (char != '0') {
System.err.println("postion " +i);
}
}
 
sedj
after running you code getting the following errors

String s = "000000-314.14";
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (char != '0') {
System.err.println("postion " +i);
}




H:\archive_java\archiving\Generalinsert.java:123: ']' expected
if (char[ii] != '0')
^
H:\archive_java\archiving\Generalinsert.java:127: '.class' expected
}
^
H:\archive_java\archiving\Generalinsert.java:126: ')' expected
}
^
H:\archive_java\archiving\Generalinsert.java:123: unexpected type
required: value
found : class
if (char[ii] != 'a')
^
Note: H:\archive_java\archiving\Generalinsert.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
4 errors

Process completed.
Please help
 
Should be :

String s = "000000-314.14";
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars != '0') {
System.err.println("postion " +i);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top