Remove Substring Occurrences in String
I have a stirng in PL/SQL
"first text {a-start} first body {a-end} test1 {b-start} secondy body {b-end} test2
{c-start} third body {c-end} end text"
a) here {a-start},{a-end},etc.. are fixed values and these can be repeated
Declare
ret_val number (10) := 1;
begin
if ( ret_val = 1) then
output : first text first body test1 test2 end text
if (ret_val=2) then
output : first text test1 second body test2 end text
if (ret_val =3) then
output: first text test1 test2 third body end text
end if;
end;
Can anbody help me.
Thank You,
Regards
Prabhakar T
Quick and dirty:
1 with v as (
2 select 1 ret_val, 'first text {a-start} first body {a-end} test1 {b-start} '||
3 'second body {b-end} test2 {c-start} third body {c-end} end text' str from dual union all
4 select 2 ret_val, 'first text {a-start} first body {a-end} test1 {b-start} '||
5 'second body {b-end} test2 {c-start} third body {c-end} end text' str from dual union all
6 select 3 ret_val, 'first text {a-start} first body {a-end} test1 {b-start} '||
7 'second body {b-end} test2 {c-start} third body {c-end} end text' str from dual
8 )
9 select case ret_val
10 when 1
11 then regexp_replace (
12 str,
13 '(^.+){a-start}(.+){a-end}(.+){b-start}(.+){b-end}(.+){c-start}(.+){c-end}(.+)$',
14 '\1\2\3\5\7'
15 )
16 when 2
17 then regexp_replace (
18 str,
19 '(^.+){a-start}(.+){a-end}(.+){b-start}(.+){b-end}(.+){c-start}(.+){c-end}(.+)$',
20 '\1\3\4\5\7'
21 )
22 when 3
23 then regexp_replace (
24 str,
25 '(^.+){a-start}(.+){a-end}(.+){b-start}(.+){b-end}(.+){c-start}(.+){c-end}(.+)$',
26 '\1\3\5\6\7'
27 )
28 end str
29* from v
SQL> /
STR
first text first body test1 test2 end text
first text test1 second body test2 end text
first text test1 test2 third body end text
3 rows selected.
Similar Messages
-
How to remove the comma from string
Hi,
I Have string like below :
String some1="123,44.22";
I want to remove comma from string and final output should be 12244.22.
public class getOut{
public static void main(String args[]){
String some1="123,44.22";
getChars(int 0,some1.length(),char[] dst,0);
can somebody in the forum give me idea how to remove comma from the String and
have a string without comma.
Thanks
Jackint idx = oldString.indexOf(',');
if(idx >= 0)
newString = oldString.substring(0, idx) + oldString.substring(idx + 1);or for jdk 1.4 and later
str = str.replaceAll(",", ""); -
Regular expression for 2nd occurance of a substring in a string
Hi,
1)
i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
in this i want the second occurance of afn and change that one only...
which regular expression i have to use...
Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
2)
How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
Thanks in advance,
Venkatjavafreak666 wrote:
Hi,
1)
i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
in this i want the second occurance of afn and change that one only...
which regular expression i have to use...
Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
2)
How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
Thanks in advance,
VenkatWhat do you mean by using a regex to get the index of a second substring? There is not method in Java which uses regex to et the index of a substring.
There are various indexOf(...) methods for this:
String text = "axe,afn,sdk,jdi,afn,mki,mki";
String target = "afn";
int second = text.indexOf(target, text.indexOf(target)+1);
System.out.println("second="+second);Of course you can find the index of a group like this:
Matcher m = Pattern.compile(target+".*?("+target+")").matcher(text);
System.out.println(m.find() ? "index="+m.start(1) : "nothing found");but there is not single method that handles this: you'll have to call the find() and then the start(...) method on the Matcher instance, so the indexOf(...) approach is the favourable one, IMO. -
it sounded prettty easy..
I know the first part of my String is <html><center><p> and the last part is </p></center></html>
but for saving it into the database I want to remove the HTML parts..
I know how much characters the html stuff is.. I know what the html is.. how do I remove it from my string?If your String always starts with <html><center> and always ends with </center></html> you can use:
int startLength = "<html><center>".length();
int endLength = "</center></html>".length();
String withoutHtml = myString.substring(startLength, myString.length() - endLength); -
How to search for perticular substring in given string.
Hi, Can any one tell me how to search for perticular substring in given string.
example:
I have to search for CA in given Order type it may be CA10 or CA15. Please Do the needful.Hi Aniruddha,
check this...
Data var string,
var = 'India'.
search var for 'Ind'.
if sy-subrc = 0. " var having ind
Message 'Ind found' type 'I'.
else . "var not having ind
Message 'Ind not Found' type 'I'.
endif.
thanx
bgan. -
Looking for a substring within a string (regexp)
Hi folks,
I want to select a substring from a string
string:
21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY
or
21;0000;4145054;4;A;4 goldglamsnu XEOFX,198877,XEOFX YWY,1,YWY
I'm looking for the substring:
YWY,1,YWY
and try this SQL statement
SQL> select REGEXP_substr('21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY' ,',[^YWY]+[0-9]')
2 from dual;
REGEXP_
,117107
I don't know where my mistake is. Can anybody please help me?
Database Version 11G R2
Thanks,
ben
Edited by: ben512 on May 14, 2013 5:05 PMHi,
ben512 wrote:
Hi folks,
I want to select a substring from a string
string:
21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY
or
21;0000;4145054;4;A;4 goldglamsnu XEOFX,198877,XEOFX YWY,1,YWY
I'm looking for the substring:
YWY,1,YWYWhy do you want that substring. Do you always want the last 9 characters of the string?
If you're looking for a substring that starts with 'YWY', and then has any number (including 0) of commas, digits, and additional 'YWY' strings after it, then:
REGEXP_SUBSTR ( str
, 'YWY[,[:digit:]]*)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, maybe 5 or 10 rows), and also post the results you want from that data. Include examples of any special cases you need to handle (e.g., the target pattern is not found at all, or it is found at 2 different places in the string).
Explain, using specific examples, how you get those results from that data. Say what your business rules are.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Searching for a substring within a string
can someone reccomend a simple way to search for a substring within a string and count the number occurences of that substring.
The substring and the string will be provided as command line parameters.
Thanks
ggA simple way would be to use the indexOf methods in String:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
Not sure what this has to do with event handling though :-P -
wondering.. anyone knows how to remove characters in a string
e.g.
string: applepie
after removing last 3 chars become "apple"
thanks...That of course will only work for this example. Better solution is to use indexOf() to locate the position of the string you wish to remove. If the string you wish to remove is in the middle, then you will have to do a bit of extra work and concat two substrings.
-
How to remove new line from string
I have a string say following
String line = "one\ntwo\nthree";Now i am trying to remove new line from string. For this i did following
String txt = line.replaceAll("\\n","");But i see still new line is occuring. Is it correct way. Please advice me.Ok. I was just using \n instead of \r\n. And i am in windows. I will give a try with \r\n
Ok i tried using following , but it doesnt work.
line = line.replaceAll("\\r\n","");Am i missing anything here. Please guide me.
Edited by: ArpanaK on Oct 8, 2007 4:44 PM -
Hi!
I have a question
Can i cut a substring from a string?
If yes how is possible?
Can you help me with an example?
ThanksHi!
I have a question
Can i cut a substring from a string?Yes
If yes how is possible?You shoould read the API for String, there is a method called substring
Can you help me with an example?You wont need one if you read the API -
Hi,
I have some issue while configuring the RAT(Real Application Testing), got error while preprocessing the capture workload on test database. My source target is 11.2.0.3 and destination target is 11.2.0.3.3 database. Below is the error. Below is the error from failed jobs log file.
substr outside of string at /opt/oracle/Middleware/agent11g/EMStage/PAF/Job_CAAD88CFA1160066E0430A5108892E78_dest/untar.pl line 56.Google
http://www.perlmonks.org/?node_id=572129
http://lmgtfy.com/?q=substr+outside+of+string+at -
Hey All Gurus,
I have a string IEQUS94 I want to remove ieq from the string... how to do that?? Any thoughts!!
Will reward point... for sure!
Thanks Nina.There is a few ways to do this depending on some assumptions.
Assumption 1, that IEQ is always the first 3 characters. If that is the case.....
data: str type string.
str = 'IEQUS94'.
shift str left by 3 places.
Regards,
Rich Heilman -
Searching for the nth occurrence of a substring in a string
I need to search for the 63rd occurrence of a substring <i4> and replace it with <string>. Is there an easy way to do this?
Edited by: sarcasteak on Jun 16, 2009 11:52 AMnevermind I got it, if anyone was curious
int z = 0;
while(z<63)
index = index2+3;
index2 = result.indexOf("<param>", index);
resultTest = result.substring(index2);
//System.out.println(index2 + " :" + resultTest );
z++;
String originalSubstring = (result.substring(index2);
String modifiedSubstring = "";
modifiedSubstring = originalSubstring.replaceFirst("<i4>","<string>" );
modifiedSubstring = modifiedSubstring.replaceFirst("</i4>","</string>" );
String fixedString= result.replace(originalSubstring, modifiedSubstring);
System.out.println(fixedString);Edited by: sarcasteak on Jun 16, 2009 12:32 PM -
I have a column that contains a list of users all pipe separated. I am writing a script to rebuild this field and need to find a way to remove any duplicate user entries that might be contained in the string. Can someone please help me with the sql to remove the duplicates from the string and update the field?
Example:
Table: REPORTCONFIG
Column: EMAILNAMES
'A.Anderson||B.Dawkins||D.Cowen||A.Anderson||J.Rowling'
Also I have to include in my script a way to remove pipes that might be at the end of the string. If someone could help me on that front I would appreciate it as well.
Edited by: 943224 on Jun 27, 2012 10:41 AMIt looks like Tom's solution will convert one string. And it looks a little complicated:
with data as
( select token, rownum rn
from ( select distinct
trim( substr (txt, instr (txt, ',', 1, level ) + 1
, instr (txt, ',', 1, level+1)
- instr (txt, ',', 1, level) -1 )
) as token
from ( select ',' || ltrim(rtrim('two,one,three,one,two,three,two,one,one,four',','),',') || ',' txt
from dual
) connect by level <= length(txt)-length(replace(txt,',',''))-1
select ltrim( max( sys_connect_by_path(token,',') ), ',' ) || ',' str
from data
start with rn = 1
connect by prior rn = rn-1 ;It would be nice to have it work on a whole table of data.
I came up with this, but there's one thing I don't like. The "999" hard-coded in the query. It actually only needs to be bigger than the most entries in a string. I'm not sure how to calculate that value dynamically and still keep the query relatively simple.
with smpl_data as
( select 1 id, 'sam,rob,rob,joe,rob,sam' as txt from dual union all
select 2 , 'two,one,three,one,two,three,two,one,one,four' from dual union all
select 3 , 'a,s,g,d,s,d,s,a,d,s,g,d,s,a,g,a,s,d,f' from dual
select id
, listagg(sngl_val, ', ') within group (order by sngl_val) as no_dup_list
from ( select distinct id, lower(trim(regexp_substr( txt, '[^,]+', 1, seq ))) as sngl_val
from ( select a.id, b.seq, a.txt
from ( select id, txt, regexp_count(txt,',')+1 as n from smpl_data ) a
join ( select level as seq from dual connect by level <= 999 ) b on ( a.n >= b.seq )
group by id
order by id
;Edited by: SK1 on Jun 27, 2012 1:13 PM -
What's the best way to extract data (a substring) from a string?
Hi,
I have a field being returned from a function call and the data looks like this:
sfaqwe4|89uuuroeoi0|kjg3j90493 (It's data...pipe...data...pipe...data)
What is the best technique to use to extract the middle set of data between the two pipes?
Is the any prewritten method to separate the data, or do I have to loop thru the field looking for the pipes, etc.?
Thanks for your help,
Andy<<Copy paste from http://careerabap.blogspot.com/2009_08_01_archive.html - user notified, points removed>>
Hi,
The WRITE statement is what we use to substring a field. The syntax is as follows:
WRITE fieldname+starting_position(field_length) to variable
The fieldname is the source (or input). The plus sign precedes the starting position of the substring. The first position in the string is 0. Immediately after (no space) comes the length of the substring you are going to use. You can also substring the variable that you are writing the string to (the target).
You can also use function module 'STRING_SPLIT_AT_POSITION'.
Best Regards,
Edited by: nihad omerbegovic on Dec 14, 2009 3:03 PM
Edited by: Matt on Dec 20, 2009 4:13 PM
Maybe you are looking for
-
How can I remove an email address once it's been used?
Once upon a time, I hit "reply all" to an email sent by a friend. This email had 97 addressees, and now they're in my Mail program. Only about eight of them are people I know. When I sent individual emails to crowdfund recently, I accidentally sent t
-
I got my DVD made and thought I was home free. I have tried burning a disk directly from iDVD & have tried "Save as Disk Image". I keep getting a ''Multiplex Error". Either way it won't finish burning my movie. My DVD is 2.41 GB. I have 250 GB of fre
-
What is the size of a rowversion
Hi, https://msdn.microsoft.com/en-us/library/ms182776.aspx states : ...Is a data type that exposes automatically generated, unique binary numbers within a database. rowversion is generally used as a mechanism for version-stamping table rows. The stor
-
How can you scroll between mail messages in Lion mail?
In leopard and snow leopard, you could scroll between messages in mail with a 3 finger gesture. this feature seems to be disabled in lion....or am i missing something? Is there any way to use gestures to scroll between messages in mail?
-
Cable provider slowing down my Mac
I use Charter and I notice in the evenings that my mac is dog slow. Even stuff that does not require internet access runs sluggish. Is this just a issue with Cable modem providers? This kind of reminds me of the soft modem days when they would slow d