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 suggestions
I 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.
Similar Messages
-
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 -
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. -
Extract multiple data from long string
I am working in Crystal Reports XI looking at an SQL database. How can I pick up several different data bits from a realy long string? Each element I want is preceded by "Old Value =" or "New Value =". The problem is that there are up to 4 different sets of these "Old Value =", "New Value =" so I can only get the first set if I use "InStr" to find "Old Value =" or "New Value =".
Since they are preceded by unique headings like "RuntimeMinutes", I thought I could use "InStr" to find that "RuntimeMinutes" or whichever and then use that value as the location number nested in another "InStr" to find "New Value =" and nest it all in a "Mid" expression. But however I did it I got an error highlighting that "InStr" nested in "InStr" saying it was not an integer or the value was less than 1.
Any ideas?The way that I'd deal with this is by creating formula fields for each value that you want to extract. In the sample below, I'm assuming your string looks something like this:
RuntimeMinutes OldValue=123 NewValue=234 DbReads OldValue=12345 NewValue=34567
The formula for {@Runtime Minutes Old Value} would then look like (basic syntax):
dim pos as number
' Find where RuntimeMunutes old and new values start:
pos = InStr({really long string}, "RuntimeMinutes")
' Find first OldValue after RuntimeMinutes:
pos = InStr(pos + 14, {really long string}, "OldValue") ' 14 = Len("RuntimeMinutes")
' Pull out the value:
formula = val(mid({really long string}, pos + 9,
Instr(pos + 9, {really long string}, " ") - pos - 9)) ' 9=Len("OldValue=")
And do the same for all of the other values you need.
HTH,
Carl -
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 -
Hi,
I am curious if there is an easy way to extract an int value from a String.
For example, "Rb23" to get 23. The length of the part in front of the integer is variable.
Thanksthis seems to work:
public int extract(String s) {
String result = "";
char c[] = s.toCharArray();
int j = c.length-1;
if (!Character.isDigit(c[j])) {
return 0;
do {
result+=c[j--];
} while (j > 0 && Character.isDigit(c[j]));
return Integer.parseInt(new StringBuffer(result).reverse().toString());
}it will return 0 if no numbers are found at the end of the string -
Extract numbers from mixed string.
How do I extract numbers from a mixed-character string?
These are house numbers and I have some exceptions - examples below.
How do I get rid of the letter/dash part, and keep the numeric part only?
38A
5600B
23-A
Thanks a lot.
-JohnIt does not work if you have a string like 3343S##@1~!234
OP, you can try this:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> with t as(
2 select '38A' c1 from dual union all
3 select '5600B' from dual union all
4 select '5Bas@#$%1SDf3ff`~7' from dual union all
5 select '3343S##@1~!234' from dual union all
6 select '23-A+9' from dual )
7 --
8 select c1,regexp_replace(c1,'[^[:digit:]]') only_num from t;
C1 ONLY_NUM
38A 38
5600B 5600
5Bas@#$%1SDf3ff`~7 5137
3343S##@1~!234 33431234
23-A+9 239
SQL> -
Extracting data from a string of characters
Hi,
I have a problem that I am having difficulty solving, if anyone has any bright ideas it would be a great help.
I have a description field in one of my tables and the description would read something like
my website can be found at www.mywebsite.com, and it is great
I want to be able to extract the web address from this sentance, so the result would be
www.mywebsite.com
I can do this specific for one sentance but I can't find a way to do it for many different sentances.
cheers in advanceIf you're using 10g, you probably want to do something with regular expressions:
SQL> with strings as (
2 select
3 'my website can be found at www.mywebsite.com, and it is great' str
4 from
5 dual
6 union all
7 select
8 'my website can be found at WWW.myWebSite.com, and it is great'
9 from
10 dual
11 union all
12 select
13 'our web address is www.mywebsite.co.uk' str
14 from
15 dual
16 union all
17 select
18 'http://www.mywebsite.com/great'
19 from
20 dual)
21 select
22 s.str
23 , regexp_substr(s.str, 'www\.[a-z0-9-\.?]*', 1, 1, 'i') extr
24 from
25 strings s
26 /
STR EXTR
my website can be found at www.mywebsite.com, and it is great www.mywebsite.com
my website can be found at WWW.myWebSite.com, and it is great WWW.myWebSite.com
our web address is www.mywebsite.co.uk www.mywebsite.co.uk
http://www.mywebsite.com/great www.mywebsite.comYou'd be better asking this kind of thing on the PL/SQL (and definitely better asking someone other than me anything further about regular expressions!) -
select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionI want to extract xyz_xyz,abc_abc words from the string ' select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'') '
i have tried with this query...
select regexp_substr('select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'')', 'trunc[^'''']+''') from dual
can some one help me on this?
Thanks,
MikeHi, Mike,
Mike wrote:
I apologize for this..
create table TEMP_TABLE ( col1 varchar2(10),col2 varchar2(10));
insert into TEMP_TABLE values(' xyz ','abc ');
insert into TEMP_TABLE values(' xyzxyz ','abcabc ');
insert into TEMP_TABLE values(' xyz123 ','abc546 ');
insert into TEMP_TABLE values('xyz','abc');
commit
select * from TEMP_TABLE where trim(col1) ='xyz' and trim(col2) ='abc'
desired output
col1,col2
So the correct output is one row, containing these 9 characters
col1,col2which do not appear in the table. is that right?
How is that output related to the data that is in the table? Do you want that output to appear if there are any rows where TRIM (col1) = 'xyz' and TRIM (col2) = 'abc' (for example, either of these two rows from you sample data:
insert into TEMP_TABLE values(' xyz ','abc ');
insert into TEMP_TABLE values('xyz','abc');), and would you want the result set to contain no rows if the table contained no row like that?
If so,
SELECT DISTINCT
'col1,col2' AS desired_output
FROM temp_table
WHERE TRIM (col1) = 'xyz'
AND TRIM (col2) = 'abc'
;I hope this answers your question.
I have a feeling that it doesn't, or perhaps you have more than one question, since this your earlier messages seemed to have something to do with locating text that was surrounded by single-quotes, and the sample data you posted doesn't contain any single-quotes. -
How to find number from text string??
Hi All,
Can you tell me how to find/ fetch number from string?
is there any function module for this.?
for example , I have string like "+++++1000000589+++"
and I need to fetch the invoice no 1000000589 from the above string..then How to do that? Letters may come first or number may come first and latter text...
Regards,
MrunalYou can do like this.
The below mentioned is code separate material
DO 18 TIMES.
LV_C = LV_C + 1.
LV_C1 = LV_C - 1.
IF GW_MATNR-MATNR+LV_C1(1) CN '0,1,2,3,4,5,6,7,8,9' .
IF ( ( LV_MAT EQ SPACE ) ) ." and ( lv_prefix eq space ) ) .
LV_PREFIX = 'X'.
CONCATENATE GW_TEMP-PREFIX GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-PREFIX.
ELSE.
LV_SUFFIX = 'X'.
CONCATENATE GW_TEMP-SUFFIX GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-SUFFIX.
ENDIF.
ELSEIF ( ( LV_SUFFIX EQ SPACE ) ) .
LV_MAT = 'X'.
CONCATENATE GW_TEMP-MATNR1 GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-MATNR1.
ELSEIF ( ( LV_MAT EQ 'X' ) ) .
CONCATENATE GW_TEMP-SUFFIX GW_MATNR-MATNR+LV_C1(1) INTO
GW_TEMP-SUFFIX.
ENDIF.
ENDDO. -
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 -
Help: how to extract digits from a string?
Hi,
I am trying to make a formatted phone number report. The field is VARCHAR2(20). There might be some sort of irregularities. What I need to do are in two steps:
1. extract all digits in order;
2. format the output as (xxx) xxx-xxxx
Any suggestions?
Thank you in advance.
JimmyThis might be of some use to clean up the phone numbers.
drop table phone_numbers;
create table phone_numbers
(phone varchar2(20));
insert into phone_numbers(phone) values ('(111)-555-1212');
insert into phone_numbers(phone) values (' 111 555 1212');
insert into phone_numbers(phone) values ('#555-1212');
insert into phone_numbers(phone) values ('Bob @ 555-1212');
commit;
select phone, translate(phone,'0123456789()-.@#* ','0123456789') edited_phone
from phone_numbers;
PHONE EDITED_PHONE
(111)-555-1212 1115551212
111 555 1212 1115551212
#555-1212 5551212
Bob @ 555-1212 Bob5551212You can see by the last example that the search string in the translate function should contain every character you can type on a keyboard. -
How to extract substring from a string based on the condition ??
Hi,
I'm having a very large string which as below
EQD+CN+SAMPLE18767+2200+++5'
NAD+CA+FIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++GOOD'
FTX+AAA+++ONE'
EQD+CN+SAMPLE18795+2200+++5'
NAD+CA+TIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++SECOND'
FTX+AAA+++IS FAIR'
similarly FTX+AAA as above and it goes on
i tokenized each segment with delimiter as ' and able to read each segment.
Now i want to concatenate the FTX+AAA in a single segment if more than one FTX+AAA with IMMEDIATE below
The output is as follows
EQD+CN+SAMPLE18767+2200+++5'
NAD+CA+FIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++GOOD,ONE'
EQD+CN+SAMPLE18795+2200+++5'
NAD+CA+TIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++SECOND,IS FAIR'
similarly FTX+AAA should be concatenated if it has similar FTX+AAA IMMEDIATE below.
The FTX+AAA segments can come any number of times immediate below
Please help me how we can do this??? Can anyone help me with the code snippet to do this?
Thanks,
KathirEncephalopathic wrote:
You've posted > 300 times here and you still don't respect the rule regarding notification of all cross-posts? [http://www.java-forums.org/advanced-java/30061-how-extract-substring-string-based-condition.html]
Do you think this this will help convince others to help you?See also [http://www.coderanch.com/t/500088/java/java/extract-substring-string-based-condition|http://www.coderanch.com/t/500088/java/java/extract-substring-string-based-condition]. -
How can i parse the number from the string each time automatic ?
I have this two lines:
last_file = fi[fi.Length - 1].FullName;
string lastFileNumber = last_file.Substring(86, 6);
In last_file i have: C:\\Users\\chocolade1972\\AppData\\Local\\mws\\My Weather Station\\radar_temp_directory\\radar000142.gif
So i counted and found that the number in this case 000124 is starting from index 86 and length 6
But for example on my brother pc the directory is shorter the name is not chocolade1972 so the index is incorrect.
It's not 86.
How can i use the Substring to find the correct index every time on any pc that have a differenet directory length ?
In this case it's working fine on my pc for any image i can get the number no problems. But i want it to work also on other pc's.You can use Regex to match the filename you want.
Like Giovhan suggested you can first get the filename like:
string result;
result = Path.GetFileName(fileName);// in your example result = radar000142// in my regex I assume that a file can have a number of digits between 5 to 7 digits.Regex filenameRegex = new Regex("\d{5,7}");string number = filenameRegex.Match(result).Value;// by that way you can retrieve all numbers between 5 to 7 digits regardless of filename whether contains all 6 digits// or file that may contain 5 or 7 digits // You can play with the Regex code to decrease or increase number of digits by changing the numbers
Maybe you are looking for
-
Change the background color of a disabled JtextField
Hi, How can I change the background of a disabled JTextField ? When a JTExtField is disabled it becomes grey but I would like to change to another color. you can change the background of a disabled combobox (UIManager.put("ComboBox.disabledBackground
-
How do I install Snow Leopard on a Macbook with a cracked screen?
I've been successfully using my 4 year old Macbook with an external monitor. Now that I'm trying to instal Snow Leopard when it gets to the first instal screen after I restart it, it will only show extended display, not mirror display. Nothing happen
-
HELP: Latest Security Update hangs during startup
I did two updates, the latest Security Updates for Tiger OSX on my G4, mirror door and also the latest iTunes. After all the downloads it asked me to reboot. Now I get the gray Apple with an endless spinning clock. I did repair disk permissions via h
-
Hello, I was at school with my Macbook Pro (We have to take them to school), and someone was walking past my desk and knocked my Macbook of the table. Of course I was very annoyed, and to make things worse it was open as it fell and hit the ground. T
-
Adding Lens to Filter Panel - Bridge CS4
Very new to Photoshop and Bridge CS4 so stilling learning the basics of the applications. After installing I believe I saw Lens in the Filter Panel on the left side of the screen. I no longer see that item to open it up. In fact right clicking in the