Urgent pl.  I want to extract float from string (%f %s) or (%s %f) separate

I want to extract float from string (%f %s) or (%s %f) separated by tab, whitespace etc., Since I am using jdk1.3.1 I can't use regular expression can anybody suggest a simple (one or two or few line code - compact) to get the float in (sign+/-)#.#### format ignoring other characters ?
I tried:
e.g.,
String d="4.000 [tab]4";
source string resulted from "SUBSTRING query of mySQL" can be of :
" -4.543 XYZ ",
" XYZ -4.546 ",
" xx-yy 6.58 3 ",
"6.0 xxx yyy zzz",
the expected results for float from the string should be:
-4.543
-4.546
6.580
6.000
If String containing data separated by comma:
e.g.,
"4.120     1     ,
AAXXFE     ,4.206     1     ,
     4.000     1,
     4.201     1,
     4.189     1,
     4.204     1,
S     DDERSF-RSA"
The result should be: "4.120,4.206,4.000,4.201,4.189,4.204,0.000"
The string is created by:
ResultSet rs1 = stmt.executeQuery(S1);
while (rs1.next()) {  
String d = rs1.getString("SUBSTRING(FIELD1,LOCATE(\""+s2[i]+"\",FIELD1)+"+ k_st + ","+ length+")");
System.out.print(d+",");
May be I don't know how to use the following:
float f1 = Float.parseFloat(d);
===
String pattern = "###.###";
//float value = -2100.578f;
DecimalFormat myFormatter = new DecimalFormat(pattern);
String output = myFormatter.format(d);
System.out.println(d+" " + pattern + " " + output);
===

Hi
You made the best choice. JRegex is closer to java.util.regex.* and fine works with excellent performance in any JVM version so you can use examples/tutorials from both JRegex and Java.Sun.Com to learn more about regular expression.
About the regular expression in my last post, there are two capturing groups: the first for float numbers in IEEE format specification (also see Java Language Specification) and the second for any sequence of chars, groups using with any amount of blank spaces (spaces, tabs, etc :: see regular expression definition) as delimiter. The anchors "^" and "$" are being used to exactly match pattern in target string and you can relax this constraint as needed.
How to use JRegex? no secrets!
import jregex.*;
// a float number and string with any blank delimiter
String patternString ="^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?)\s+(.*)$";
Pattern pattern = new Pattern(patternString); // different from Sun regex package syntax
// below is identical in both packages
Matcher m = pattern.matcher(anyTargetString);
if (m.matches()) {
  Double d = Double.parseDouble( m.group(1) );
  String scratch = m.group(2);
  // your stuff goes here
..Remember to put JRegex jarfile in classpath!
Regards and Success.

Similar Messages

  • We want to extract mailboxes from exchange bkf file?

    We want to extract mailboxes from exchange bkf file? It there any manual method to get back mailboxes from bkf? Please suggest. It's urgent!
    Don't recommend me any third party software, please!

    Hi , 
    Then you could use the recovery storage group feature in exchange 2007 to extract the items from the restored backup for the selected mailboxes .
    Rererence link : http://www.msexchange.org/articles-tutorials/exchange-server-2007/high-availability-recovery/Working-Recovery-Storage-Groups-Exchange-2007.html
    Thanks & Regards S.Nithyanandham

  • Hi i am new to labview. i want to extract data from a text file and display it on the front panel. how do i proceed??

    Hi i am new to labview
    I want to extract data from a text file and display it on the front panel.
    How do i proceed??
    I have attached a file for your brief idea...
    Attachments:
    extract.jpg ‏3797 KB

    RoopeshV wrote:
    Hi,
    The below code shows how to read from txt file and display in the perticular fields.
    Why have you used waveform?
    Regards,
    Roopesh
    There are so many things wrong with this VI, I'm not even sure where to start.
    Hard-coding paths that point to your user folder on the block diagram. What if somebody else tries to run it? They'll get an error. What if somebody tries to run this on Windows 7? They'll get an error. What if somebody tries to run this on a Mac or Linux? They'll get an error.
    Not using Read From Spreadsheet File.
    Use of local variables to populate an array.
    Cannot insert values into an empty array.
    What if there's a line missing from the text file? Now your data will not line up. Your case structure does handle this.
    Also, how does this answer the poster's question?

  • Extract date from string in T-SQL

    Hi,
    I am having one field(AT_TEXT) in my database that has below kind of values. I want to extract date from this string but the issue is all rows has different format.
    1)One Month Lttr sent on 3/12/2009 due to
    2)One Month Letter sent on 1/15/2009 due to
    3)One Month letter sent on7/15/2011.The amount due             - This has no space between on and 7 and . after yr
    4)One Month letter sent on 7/16/12 due to        - This has 12 instead of 2012(2 positions after 2nd slash/)
    Can anyone please help me to write query to extract date from this string?
    Vicky

    Hi Jingyang
    Li,
    I checked your query and it looks good but I have one issue. So when we reverse it, it looks like below and it is talking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.
    I realize from your query that you are trying to reverse the value and then try to find out 1st Numeric value from that string, but my whole string has another numeric value at the end, like 
    "One Month Letter on 1/15/2009 due to non-pmt of prems-amt to avoid DE is $57.80"
    So when we reverse it, it looks like below and it is taking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.         
    "08.75$ si ED diova ot eud tma - smerp fo tmp-non ot eud 9002/51/1 no retteL htnoM enO"
    Also sometimes I have $ amount at the end and sometimes I don't have any $ amount at the end, like below,
    "One Month letter sent on 10/15/2012 due to non-payment of premiums. The amount due to avoid dise"
    Can you please modify your query which takes only date part not the $ amount and give me?
    Thank you so much for your help 
    Vicky

  • I want to extract data from a PDF using Java

    I would prefer to extract data from a PDF and convert it to XML. Is there an API that will convert a PDF to some Adobe format XML? Ideally I would like to add some JAR files to my classpath, similar to PDFBox. I don't want to install a bunch of server side componets or anything like that.
    Thanks!

    Thank you for the reply!
    If I installed the server side components, how would a Java client invoke a service to export data from a PDF? RMI, Web Services?

  • I want to extract audio from a video file into logic

    I have a video thats in the .WMV format and i want to extract certain bits of audio from it, how can i do this within Logic Pro 7.

    A quick google search on "convert WMF to quicktime" came up with this program: http://www.programurl.com/software/quicktime.htm
    Never used it, but it might be what your looking for?
    BTW, did you try just exporting the audio in WMP? Is that possible? I obviously dont use it You may also try to drag the file into logic and see what happens. Though I doubt it will work, its worth a try.

  • More efficient way to extract number from string

    Hello guys,
    I am using this Regexp to extract numbers from a string, and I doubt that there is a more efficient way to get this done:
    SELECT  regexp_replace (regexp_replace ( REGEXp_REPLACE ('  !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 |  " ' , '[[:punct:]]',''), '[[:space:]]',''), '[[:alpha:]]','')  FROM dual
    {code}
    Is there a more efficient way to get this done ?
    Regards,
    Fateh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Or, with less writing, using Perl syntax \D (non-digit):
    SELECT  regexp_replace('  !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 |  " ','\D')
      FROM  dual
    REGEXP_REPLACE(
    003240008702234
    SQL>
    {code}
    SY.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Extract information from string

    hi,
    I am working on complex number and i stuck on phase..
    i have string which contains "+2.0+ -0.3I" and i want to extract real and img part.
    how should i do that one...
    i tried parse.compile.split but it's not working and reg ex for above string i am using is "[+|-]?[0-9]+\\.[0-9]*[+|-][+|-]?[0-9]+\\.[0-9]*"
    can any one help me out with this problem please...
    thanks in advanced....

    try splitting either by "-" or "+", if one one of them gives you an array of size one, try the other.

  • Want to extract month from a date !! how ??

    Hi,
    I am trying to group records in an ALV report based on a date field. I want to actually group them based on the month !! How can I determine/extract the month and group by it in my ABAP program.
    For. e.g. if the user choose a date range in the selection criteria such as 10/10/2005 to 11/20/2005 then I want the data to be displayed as two groups , one for each month !!
    thanks

    I would suggest breaking the month into another field. When building your ITAB which will be used in the ALV, add another field to the ITAB called MONTH.  Before appending the line to the ITAB, break the month off and put it in this field.
    itab-datum = some_date.
    itab-month = some_date+4(2).
    append itab.
    Now you have the month by itself, you can now group and subtotal by the month.
    Regards,
    Rich Heilman

  • I want to extract data from oracle dump file (.dmp) using oracle database or any other tools.

    There is import which provides me data as graphical way. But i need extract data in such a way so that i could able to use in my application.
    thanks,
    mohan

    This isn't a SQLDeveloper question. You will get better answers in the Database - General forum.
    Oracle dump files produced by the exp or expdp utilities are inproprietary formats which can only be read by the imp or impdp utilities respectively.
    The best way to get data out of a dump file is to import it into a database and then extract it to plain text files using SQL.
    Alternatively, leave it in the database and your application can access it there.
    The exp dump file is mostly plain text, but the format is not published so you could waste a lot of time figuring it out.

  • Extracting data from string

    Can anyone point me in the right direction as to how URL's
    can be extracted from a string?
    Or at least find the start and end positions...
    EG:
    I want to get the URL's from the "a href"'s...
    String- "The quick brown fox jumps over the lazy dog, <a
    href="
    http://www.example1.com">click
    here</a>. The quick brown fox jumps over the lazy dog, <a
    href="
    http://www.example2.com">click
    here</a>.".

    Hi,
    You can do this by using the "anchors" object in
    "Javascript".. Below is the Sample Code..
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="
    http://www.w3.org/1999/xhtml">
    <head>
    <script language="javascript">
    function fnCheckAnchors()
    for (var i=0;i<document.anchors.length;i++)
    alert(document.anchors.item(i));
    </script>
    <meta http-equiv="Content-Type" content="text/html;
    charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form name="form" action="" method="post"
    onsubmit="fnCheckAnchors();">
    <a name="1" href="
    http://www.yahoo.com">Yahoo</a><br
    />
    <a name="2" href="
    http://www.google.com">Google</a><br
    />
    <a name="3" href="
    http://www.altavista.com">Altavista</a><br
    />
    <input type="submit" name="submit" value="Submit" />
    </form>
    </body>
    </html>

  • Need a way to extract substring from string in oracle

    Hi all,
    I have one requirement related to extracting string from a paramater.
    suppose the string may like this in various format
    string:= 'This my string <Rid//problem/123456>'
    or
    string:= '<Rid//problem/123456> This my string'
    or
    string:= ' This is <Rid//problem/123456> my string'
    Now my requirement is i need to extract 123456 using pl/sql block.
    is there any way in oracle to get this thing done.
    Thanks n regards
    Laxman

    Hi,
    What version of Oracle ?
    How do you delimit the string to extract ?
    - always between the last / and before the >
    - the last string mande of number ?
    - the first string made of number ?
    Here are 3 possible answers :SQL> with s as (
      2  select 'This my string <Rid//problem/123456>' s from dual
      3  union all select '<Rid//problem/123456> This my string' from dual
      4  union all select ' This is <Rid//problem/123456> my string' from dual
      5  )
      6  select s.s,
      7  regexp_replace(s,'^.*/([0-9]*).*$','\1') r1,
      8  regexp_replace(s,'^[^0-9]*(.*?)[^0-9]*$','\1') r2,
      9  regexp_replace(s,'^.*/(.*?)>.*$','\1') r3
    10  from s ;
    S                                        R1       R2       R3
    This my string <Rid//problem/123456>     123456   123456   123456
    <Rid//problem/123456> This my string     123456   123456   123456
    This is <Rid//problem/123456> my string 123456   123456   123456If you're on 10g or more...
    Of course it also works in PL/SQL :SQL> l
      1  declare
      2  r1 varchar2(50) := 'This my string <Rid//problem/123456>';
      3  r2 varchar2(50) := '<Rid//problem/123456> This my string';
      4  r3 varchar2(50) := ' This is <Rid//problem/123456> my string';
      5  r1b varchar2(50);
      6  r2b varchar2(50);
      7  r3b varchar2(50);
      8  begin
      9  r1b := regexp_replace(r1,'^.*/([0-9]*).*$','\1') ;
    10  r2b := regexp_replace(r2,'^[^0-9]*(.*?)[^0-9]*$','\1') ;
    11  r3b := regexp_replace(r3,'^.*/(.*?)>.*$','\1') ;
    12  dbms_output.put_line('1 : '||r1||' -> '||r1b);
    13  dbms_output.put_line('2 : '||r2||' -> '||r2b);
    14  dbms_output.put_line('3 : '||r3||' -> '||r3b);
    15* end;
    SQL> /
    1 : This my string <Rid//problem/123456> -> 123456
    2 : <Rid//problem/123456> This my string -> 123456
    3 :  This is <Rid//problem/123456> my string -> 123456
    PL/SQL procedure successfully completed.Edited by: Nicosa on Jul 23, 2010 3:22 PM

  • How to extract substring from string... how to find the index?

    suppose i have a string like
    "string1 string2 string3 string4 string....stringK...stringN"
    i would like to extract the substring from string4 to stringK-1
    where stringK and string3 are pre defined strings (ie, i know exactly what stringK and string3 is).
    is there a function to extract the substring from string4 to stringK-1
    or is there a function i can use to determine the index of the end of string4 and the start of stringK?
    thks!

    If your substrings are seperated by a space (or by any other character that isn't used in any of the substrings), you could use something like StringTokenizer.
    If you wanna get real fancy, use the split method of String.

  • Extract Characters from String

    Hi
    Can anyone let me know how can i extract the letters HIJK from the following string
    Sting s = "ABCDEFGHIJKLMNOP"
    Thanks

    Thanks for that
    but if i do something like this it falls over
    String temp = s.substring(12, 3);You posted this response 2 minutes after the previous response. This means you obviously didn't take the time to read the String API to find out more information about the parameters for the method. Take some time to learn about new methods before claiming they don't work.

  • Compare and extract number from string

    Hi, all
    If I want to compare a requirement number and extract a number form a continuous data, . for example,
    the string like this ( ******** 123 ******
                                   *********456 ******
                                   *********789*******)
    and I have requiremnts that I need to extract the number is nearest greater 450, so in the above example, I need to pick 456.
    How can I result it?
    thanks

    Just extract all numbers into an array, then find the element with the smallest absolute difference. See attached (LabVIEW 7.0).
    EDIT: Sorry, If by "Nearest greater" you mean the next higher number, you can use something like in my example II. (Also LabVIEW 7.0).
    If you don't recognize an node, just right-click on it and select help.
    You still need to add proper execption handling, e.g.:
    What if no element is greater?
    What if there are multiple solutions?
    What if the string does not contain any numbers?
    Message Edited by altenbach on 10-13-2005 09:05 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FindClosest.vi ‏29 KB
    FindClosestII.vi ‏30 KB

Maybe you are looking for

  • Can't post comments to pages

    When anybody (including myself) tries to leave a comment, an error message simply says "Sorry. We are unable to process your request at this time." Is this a Mobileme thing again?

  • Problems displaying blog&photo gallery in Chrome

    Hi everyone, I'm rather new to site-creating. I've made a site with 2 photo-galleries and one blog-page in iWeb and published it to a local folder on my mac. Before moving forward and dealing with ftp-client etc., I just tried to check the general vi

  • Help with reflection in java

    hi i am new to java .I write my program in myeclipse4.0 while running the code it gives error dialogbox like javavirtualMachine says that fatal error came so program is exited.after that ArrayIndexOutOfBoundException is came. I am unable to understan

  • Data Association Between BPM Process Objects and EO,VO

    Hi I have an ADF screen where I am displaying values from database through EOs and VOs. My problem is after the user selects a value on the screen,I dont know how to map these selected values to BPM Process Data Objects. Is there not a better way to

  • Treo 680 won't sync calendar and contacts but everything else OK

    I  bought a Treo 680 off of Ebay. It is unlocked.  ATT phone but I use T-Mobile.  PHone works just fine but I can't use the Palm organizer for calendar or contacts.   I have hard reset several times.  WHen I do everything works except the contacts an