java - String function to accept the 10 digit mobile no. , discards any no. less than 10 digits, trims zeroes at the beginning -


Text after "itemprop =" text ">

When we enter the output display no later than" 00982787878 "(having 9 digits and zero) are after zero Should not be trimmed.

In the problem:

, while there is a number with only one 0 sorting

code loop has some problem as output:.

  public static string trimazoros (string mobNumber) {boolean exitLoop = true; Int count = 0; While (exit & amp; amp; mobNumber.substring (calculation) == "0") mobNumber = mobNumber.substring (0); If (mobNumber.charAt (count)! = '0') {exitLoop = false; } Calculate ++; MobNumber = mobNumber.replaceAll ("", ""); MobNumber = mobNumber.length () & lt; 10? MobNumber.substring (mobNumber .length ()): mobNumber.substring (mobNumber.length () - 10); Return mobile number; }   

If I understand your problem correctly: < Pre> public static string trimorrose (string number) {// trim zero left number = number. Substituted all ("^ 0 *", ""); // If the length is & lt; 10 gives an empty string if (number.length () & lt; 10) {return ""; } // If the length is & gt; 10, if any number trims on the left (number.length ()> 10) {number = number.replaceAll (". * * (\\ d {10}) $", "$ 1"); } Return number; }


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -