String st = "abcd";
int i=0;
while(i<st.length())
{
char c = ?........(st.substring(i,i+1));
System.out.Println(c);
i++;
}
cheq stringhow to cheq string
15 Replies - 728 Views - Last Post: 20 January 2010 - 06:58 PM
#1
cheq string
Posted 20 January 2010 - 09:10 AM
Replies To: cheq string
#2
Re: cheq string
Posted 20 January 2010 - 09:15 AM
String st = "abcd";
// edit the loop a bit
for (int i = 0; i < st.length(); i++)
{
char ch = st.charAt(i); // use the charAt() method to access characters
System.out.println(ch);
}
Hope this helps!
This post has been edited by Locke: 20 January 2010 - 09:16 AM
#3
Re: cheq string
Posted 20 January 2010 - 09:22 AM
String st ="condition";
int len = st.length();
int y= 0;
while(len>y)
{
String c = st.Substring(y,y+1);
char ch = c;
if(ch>='A'&& ch<='Z' || ch>='a' && ch<= 'z' )
{y++;
}
else{break;}
}
if(i==len){System.out.Println("valid");}
else{System.out.Println("unvalid ");}
Edited by Locke. Please, in the future -->
This post has been edited by Locke: 20 January 2010 - 09:48 AM
#4
Re: cheq string
Posted 20 January 2010 - 09:46 AM
& Please tell us what your issue is
oh and its "check" not "cheq"
This post has been edited by SwiftStriker00: 20 January 2010 - 09:47 AM
#5
Re: cheq string
Posted 20 January 2010 - 09:49 AM
if (y == len) // not 'i'
#6
Re: cheq string
Posted 20 January 2010 - 09:52 AM
String cStr = "c"; char c = cStr.toCharArray()[0];
This post has been edited by SwiftStriker00: 20 January 2010 - 09:53 AM
#7
Re: cheq string
Posted 20 January 2010 - 10:01 AM
String c = st.Substring(y,y+1);
substring is lowercased
Also, since c is a String, you cannot convert it to a char just by doing this:
String c = st.Substring(y,y+1); char ch = c;
You could, as SwiftStriker suggested, do this:
String a = "a"; char s = a.toCharArray()[0];
#8
Re: cheq string
Posted 20 January 2010 - 10:26 AM
#9
Re: cheq string
Posted 20 January 2010 - 10:29 AM
#10
Re: cheq string
Posted 20 January 2010 - 10:55 AM
But since we're talking about accessing individual characters, I'm surprised that didn't come up here. It would involve another variable to continuously go through the string, but meh.
#11
Re: cheq string
Posted 20 January 2010 - 11:05 AM
#12
Re: cheq string
Posted 20 January 2010 - 11:28 AM
boolean valid = st.matches("[A-Za-z]+");
#13
Re: cheq string
Posted 20 January 2010 - 04:47 PM
#14
Re: cheq string
Posted 20 January 2010 - 06:34 PM
char[] digit = string.toCharArray();
#15
Re: cheq string
Posted 20 January 2010 - 06:35 PM
|
|

New Topic/Question
Reply




MultiQuote








|