tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Open Symphony Core > Extract Number

Extract Number 

OSCore (Open Symphony Core) is a java library with lot of utilities and reusable components. This requires the libraries oscore-2.2.6.jar, mail.jar to be in classpath. The following example shows using TextUtils.extractNumber() API. It extracts the number from given string.

File Name  :  
com/bethecoder/tutorials/oscore/ExtractNumberTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.oscore;

import com.opensymphony.util.TextUtils;

public class ExtractNumberTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    String num = TextUtils.extractNumber("My Phone bill is 1234.56 rupees per month");
    System.out.println(num);
    
    num = TextUtils.extractNumber("a1b2c3d4e5f6g7h8");
    System.out.println(num);
    
    num = TextUtils.extractNumber("1.2.3.4.5.6");
    System.out.println(num);
    
    num = TextUtils.extractNumber("- 1 abc .2 + .3  .4  xyz   5.6");
    System.out.println(num);
    
    num = TextUtils.extractNumber("JAVA");
    System.out.println(num);
  }

}
   

It gives the following output,
1234.56
12345678
1.23456
-1.23456
0


                    Print

   



Books Recommendation

 
 
bl  br