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 / May 2004

Tip: Looking for answers? Try searching our database.

Printing strings with spaces

Thread view: 
Sarah - 14 May 2004 23:13 GMT
I am currently trying to convert a string inputted by the user, into
all lower case characters. I have discovered that my method will work
until it comes across a space in the string, at which point it stops
all together.

How do I print a string which contains spaces?

How do I convert the string all to lower case if it contains spaces?

Any help I can get will be much appreciated.
Roderick Olliver - 14 May 2004 23:19 GMT
> I am currently trying to convert a string inputted by the user, into
> all lower case characters. I have discovered that my method will work
[quoted text clipped - 6 lines]
>
> Any help I can get will be much appreciated.

System.out.println( "SpongeBob Square PANTS ".toLowerCase() );

spongebob square pants
$

Is that what you mean?
Roedy Green - 15 May 2004 01:50 GMT
>I am currently trying to convert a string inputted by the user, into
>all lower case characters. I have discovered that my method will work
>until it comes across a space in the string, at which point it stops
>all together.

None of the methods I know of fail on spaces.  Show us your code.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Mikael Laine - 16 May 2004 15:58 GMT
If you are taking the string as command-line arguments it considers the
next word after the space another argument. So if you have something like:
public static void main(String args[]){
    System.out.println(args[0].toLowerCase());
}
you need to change it to

public static void main(String args[]){
    String str="";
    for(int i=0;i<args.length;i++){
        str+=args[i]+" ";
    }
    System.out.println(str.toLowerCase());
}

But if you are not doing this, then I don't know what's wrong :)
Send in the code Sarah...


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.