Friday, March 17, 2017

[Solved] java: How to insert a character into a String at a certain position?

Lets say you want to insert "." into "B500ST90"  to make it look like "B50.0ST.90".

You can achieve this in the following ways.

      String str = "B500ST90";

1. Substring concatenation
       
      String result = str.substring(0,3) + "." + str.substring(4,7) + "." + str.substring(8);

2. StringBuilder insert

       String result = new StringBuilder("B500ST90").insert(3, ".").insert(7. ".").toString();

---------------------------------------------------------------------------------------------------

                        


If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment