#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0

    change first character to uppercase


    1) i need to know how to change a String first character to uppercase.

    2) i also how to change all characters to lower case.

    3) i also need to know how to replace a space with underscore
    eg " " to "_".
  2. #2
  3. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    if you are on unix use sed: here is a simple example of how to change any letter a with b in some file

    sed 's/a/b/g' somefile


    once you can figure out the regular expression it should be easy. if you need help with regex let me know.
  4. #3
  5. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Take a look at the docs for java.lang.String: http://java.sun.com/j2se/1.4/docs/ap...ng/String.html
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Vicksburg, MS
    Posts
    7
    Rep Power
    0
    /* Example.java
    */


    public class Example{

    public static void main(String[] args){
    Example example = new Example();
    example.test();
    }

    public void test(){
    String someString = "la la la la la la la";
    /* 1) i need to know how to change a String first character to uppercase. */
    String string1 = someString.substring(0,1).toUpperCase() + someString.substring(1);
    /* 2) i also how to change all characters to lower case. */
    String string2 = someString.toUpperCase();
    /* 3) i also need to know how to replace a space with underscore
    eg " " to "_". */
    String string3 = someString.replace(' ','_');
    System.out.println(someString);
    System.out.println(string1);
    System.out.println(string2);
    System.out.println(string3);
    }
    }

IMN logo majestic logo threadwatch logo seochat tools logo