The Artima Developer Community
Sponsored Link

Java Answers Forum
Getting one char out of a String?

1 reply on 1 page. Most recent reply: Oct 2, 2002 7:23 AM by Don Hill

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Robert

Posts: 1
Nickname: damatrix
Registered: Oct, 2002

Getting one char out of a String? Posted: Oct 2, 2002 3:54 AM
Reply to this message Reply
Advertisement
I'm making a program and I want to get a scecified character out of a String.

So I want the first char out of String Name for an example.
Then I want the second, tirth ....etc.

Can anyone explain how to that in Java, thanks.


Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: Getting one char out of a String? Posted: Oct 2, 2002 7:23 AM
Reply to this message Reply
2 ways that I can think of real quick

String s = new String("My String");
String token = null;
int length = s.length();
for{ inti=1, i<= length; i++ ){

token = s.substring( i,1);
}
or
char[] c = s.toCharArray();
length = c.length;
for{ int i=0,i< length;i++ ){

token = c[ i ];
}

HTH

Flat View: This topic has 1 reply on 1 page
Topic: how to run html which has JScript in it in the JEditorPane or JTextPane Previous Topic   Next Topic Topic: EJB question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use