Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Add any character to String on a particular location

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 311
    Comment on it

    Sometimes, we need to change some special character on String to fulfill our requirements.

    For example, we need to show phone number, i.e, 2001256443 as (200)-125-6443

    Now we use the substring method of String to solve it. We just add String on the particular location.

    String phone = "2001256443";
    String mobile = null;
    
    mobile = "(" + phone.substring(0, 3) + ")" + phone.substring(3, 6) + "-" + phone.substring(6, phone.length());
    System.out.println("Phone : "+mobile);

    O/P:

    Phone : (200)-125-6443

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: