Hi.
have you faced scenarios like you have alphanumeric String and you have requirement to use numeric String to fullfil your requirement, like if need to convert in other data type later.
so here is Magic in below programe:-
package com.neesri.sorting;
public class AlphanumericToNumeric {
public static void main(String[] args) {
// convert alphanumeric string into numeric string
String str = "a12334tyz78x";
str = str.replaceAll("[^\\d]", "");
System.out.println("Alphanumeric string to Number "+ str);
}
}
======output====
Alphanumeric string to Number 1233478
Happy Learning :)
No comments:
Post a Comment