Hyperion Brio: Computed Item Extract Number From String
I would like to extract a number from a string in a computer item. For example if I had a string such as "The customer purchased $5.00 of footballs", I would like to remove only the 5.00 from the string. I would have to use the java functions in the results. Any suggestions on how to do this?
you can do this in the Results section with a computed column using the native string functions. to break it down i have split it up a bit.
strval is you string "The customer purchased $5.00 of footballs"
position of $ = 25
Instr ( strval, '$', 1, 1 )
the starting position of the amount would then be 26
Instr ( strval, '$', 1, 1 ) + 1
position of decimal after $ = 26
Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 )
using Substr function you need to pick the string, the start value and the number of characters.
string
= strval
start position
= Instr ( strval, '$', 1, 1 ) + 1
number of characters - location of decimal minus the start position plus 3 to get the cents
= Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 ) + 3
put all together
Substr( strval, Instr ( strval, '$', 1, 1 ) + 1, Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 ) + 3 ) * 1
the multiply by 1 converts the string to number
Similar Messages
-
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,
FatehOr, 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. -
I need to extract the number, if it exists, from an alphanumeric text string. I am told that the first two characters will be alpha and the remaining character(s) will be numeric, if the numeric exists at all.
I know this is a simple formula, but I can't quite get it.Are the two alpha and remaining numeric characters always in the same position within the string?
Are the two alpha characters always going to be the same?
Is the length of the numeric value following the two alpha characters always going to be the same?
The more no answers you have to the above the tougher it will be!
Get back with the above answers and possibly copy and paste some examples of the ENTIRE strings from which you will be extracting the values and let us know which are the values you'll be pulling from within the larger string.
"I need to extract the number, if it exists, from an alphanumeric text string. I am told that the first two characters will be alpha and the remaining character(s) will be numeric, if the numeric exists at all.
I know this is a simple formula, but I can't quite get it." -
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?
thanksJust 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 -
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. -
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?
VickyHi 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 -
How to extract number from array?
I'd like to extract some number from an array.For instance,there is an array {5,0,21,3,1,2,3,71,36},labview is expected to check if there is consecutive number in it.If is,the number before the first of the consecutive number and the one just after the last of the consecutive number are extracted,then they are put into another array. If not,nothing is done.In this array,1,2,3 are consecutive,then the number 3 and 71 will be put into another array.
I thought about it for a long time but nothing came out.I am really at a loss now.Any help will be appreciated.An uploaded vi would be better.Thanks so much!!this may jus help you to get started... pls debug for error possible. You can have better solution.
(and you got to figure out yourself of how it works as I was jus simply wire them up unitl it works )
Cheers!
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010
依恩与LabVIEW
LVVILIB.blogspot.com
Attachments:
consecutive_check_example.vi 51 KB -
Extract number from long string
I have this ugly string in a column of type VARCHAR2. 34382-172.28.129.212(88:6c:de:32:51:a5)-38065-1279731239826
Is there a way to parse this string into a number (remove all letters and punctuation) when selecting from the db? Thanks for any suggestionsI wasn't sure if I got your requirements right so I wrote a statement with several solutions, in any case if you're using Version 10g or higher, regular expressions are your friends:
WITH t as (SELECT '34382-172.28.129.212(88:6c:de:32:51:a5)-38065-1279731239826' col1
FROM dual
SELECT t.col1
-- solution 1: only the first number
, REGEXP_SUBSTR(t.col1, '^\d+') solution_1
-- solution 2: all numbers (without the IP/Mac-Address)
, REGEXP_REPLACE(t.col1, '((^\d+)-|(-\d+))|.','\2\3') solution_2
-- solution 3: all digits
, REGEXP_REPLACE(t.col1, '\D') solution_3
FROM t
COL1 SOLUTION_1 SOLUTION_2 SOLUTION_3
34382-172.28.129.212(88:6c:de:32:51:a5)-38065-1279731239826 34382 34382-38065-1279731239826 343821722812921288632515380651279731239826 C. -
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
LaxmanHi,
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 -
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> -
Hi,
I have a problem with an select.
I need to compare two string columns. First column includes only a number with 9 characters:
'001234567'
Second column includes text where somewhere inside this text is the number 001234567.
'Hallo1 001234567'
I need to extract the 9 character big number out of the string. I thought using the regular expression feature could help me.
SELECT
REPLACE(REGEXP_REPLACE('hallo 001122334', '[a-z]', ''),' ') "REGEXP_REPLACE"
FROM dual;But this would exclude the number 1 after Hallo:
Result: '1001234567'
The number I look for is always 9 character long.
Thanks ahead,
TobiasYou have many variants:
with your_table as
(select
'hallo1001122334' first_column,
'001122334' second_column
from dual
select *
from your_table
where
--1) regexp_like(first_column,'.*'||second_column||'$')
--2) first_column like '%'||second_column
--3) regexp_substr(first_column,'\d{9}$')=second_column
--4) regexp_replace(first_column,'\D','') like '%'||second_columnFourth variant - includes case when chars can be between numbers in first column (for example 'hallo100a1a1a2a2a3a3a4'). -
Read only number from string and number
I have "COM4" from my I/O. how could to read number 4 only?
Thank you
Solved!
Go to Solution.Hello, i might need your help regarding this matter.
I'm current taking a reading from Arduino from 2 accerolmeter to Labview. X=0.02 Y=-0.03 Z=0.99 A=0.33 B=0.42 C=0.84 (Example)
But when i display them using Waveform Chart in labview, I need to use the array to count the position of the String from buffer which sometimes might be inaccurate due to the the value extracted.
I was told that i can use Search string from the beginning to allow the waveform to take in only the numeric.
Are you able to assist me regarding this issue?
Below attached are the pictures..
Attachments:
LabviewBlockDiagram.png 64 KB
LabviewFrontPanel.png 196 KB -
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"
ThanksThanks 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. -
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.
Maybe you are looking for
-
Logical system and rfc destination
hello all, what is the difference between logical system and RFC destination? thanks for ur help in advance. regards, vikas
-
Not able to clear out a formula field value when variables are equal to 0
I am trying to calculate the difference between a formula field from a main report and a formula field from a subreport. When i run the report i get a correct difference calculation only when both formula fields have a value different than 0. When bo
-
I turned on the ipad for the first time to charge and the apple symbol showed up then the itunes app with a picture of the charger pointing towards it. no matter what i do i can't get to the home screen
-
PLEASE HELP!! Why do my file dates change on import?
I'm trying to drag and drop iPhotos into Aperture or export a collection of files and then import them into Aperture, but the image date changes to a random date in the future when I do so. What am I doing wrong? How do I solve the problem?
-
SAP UI5 export to PDF ( Fetch data dynamically )
Hello Everyone, I am creating a utility wherein the data ( table ) would be fetched from the back end and then it would be displayed on the front end. I have follewed the approach of Chandrashekhar ( Display Smartform (PDF) in SAPUI5 ) but I want t