I am doing an app wherein the user is required to enter his mobile number. In order for my app to be user friendly, I am providing a format for them (e.g. 09XX-XXX-XXXX). After the registration process, the app will automatically text a certain number which compose the user's FirstName, Last Name and Mobile Number. In order for the server to contact the user, I must replace the '0' (which is the first character) with '+63'. Can somebody help me on how to replace it?
6 Answers
String str="09XX-XXX-XXXX"; str=str.substring(1,str.length()); try this it will replace first character from the string
4 Comments
androidBoomer
how can I replace the 0 into '+63'?
Ali Ahmad
give whole text and output to be get
Ramesh Kumar
my number is 07875780025 then it will convert all 0 to +63. i need only first 0 is change.
Ali Ahmad
Use as mention below str="+63"+str.substring(1,str.length());
just try this..
String someString = "0"; String str = someString.replace("0", "+63"); Log.v("hari", "str:"+str); or String someString = "0 9854172 common"; String str = someString.replace("0", "+63"); Log.v("hari", "str:"+str); 3 Comments
Jitender Dev
This is incorrect , it will replace '0' with '+63' in the whole string . its not what he has asked.
harikrishnan
i may not understand question.
Ramesh Kumar
my number is 07875780025 then it will convert all 0 to +63. i need only first 0 is change.
The question is duplicate of How to replace a plus character using Java's String.replaceAll method. Try the followings.
String str = "09XX-XXX-XXXX"; str.replaceFirst("0", "\\+63");