Code Snippets

  

Java Source Code


Welcome to Dream.In.Code
Click Here
Getting Java Help is Easy!

Join 118,876 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 1,873 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Simple String Manipulation

An example of some string manipulation techniques.

Submitted By: jayman9
Actions:
Rating:
Views: 2,302

Language: Java

Last Modified: July 29, 2006

Snippet


  1. import java.lang.String;
  2. import javax.swing.JOptionPane;
  3.  
  4. public class StringExercise1
  5. {
  6.      public static void main(String[] args)
  7.           {
  8.                String textString;
  9.                              
  10.                textString = JOptionPane.showInputDialog("Enter a string:");
  11.                
  12.                              
  13.                totalString(textString);
  14.                convLowerCase(textString);
  15.                replaceLetters(textString);
  16.                convUpperCase(textString);
  17.                
  18.                System.out.println();
  19.                System.exit( 0 );     
  20.           } 
  21.          
  22.           public static void totalString(String text)
  23.           {
  24.                System.out.println("The length of the string " + text + " is "
  25.                + text.length());
  26.           }
  27.          
  28.           public static void convLowerCase(String text)
  29.           {
  30.                System.out.println("Here it is in lower case "
  31.                + text.toLowerCase());
  32.           }
  33.          
  34.           public static void replaceLetters(String text)
  35.           {
  36.                System.out.println("Here it is with the a and z swapped "
  37.                + text.replace('a','z'));
  38.           }
  39.          
  40.           public static void convUpperCase(String text)
  41.           {
  42.                System.out.println("Here it is in upper case "
  43.                + text.toUpperCase());
  44.           }
  45. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month