Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2005

Tip: Looking for answers? Try searching our database.

sting to char array

Thread view: 
Carramba - 07 Apr 2005 07:24 GMT
hi!

how do I convert a string that I get from command lite to char array?
I have args[0]="this is test"
and I want to by able to print
"
t
h
i
... and so on, but Iam having hard time to converting the sting to chars
Signature

thanx in advance

______________________________

javaboi - 07 Apr 2005 07:51 GMT
> hi!
>
[quoted text clipped - 6 lines]
> i
> ... and so on, but Iam having hard time to converting the sting to chars
javaboi - 07 Apr 2005 07:53 GMT
Here's one way:
***********
String s1 ="this is one";
char[] mychars = s1.toCharArray();
for (int i = 0; i < mychars.length; i++) {
  System.out.println("The current character is: " + mychars[i]);
}
Wannabee - 07 Apr 2005 09:05 GMT
> hi!
>
[quoted text clipped - 6 lines]
> i
> ... and so on, but Iam having hard time to converting the sting to chars

Maybe you mean this? (untested)

public class Grazy {
   public static void main(String[] args) {
       if (args == null || args.length == 0) {
           System.out.println("Give a command line parameter!");
           return;
       }

       System.out.println("\"");
       // The first " is not part of the String ;-)

       char[] chars = args[0].toCharArray();
       for (int i = 0; i < chars.length; i++) {
           System.out.println(chars[i]);
       }

       // Maybe you want it also to end with a "
       System.out.println("\"");
   }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.